Skip to content

Commit f5219c5

Browse files
committed
perf: use ${var##} instead of basename 🎛️
no subprocess fork, faster
1 parent c547856 commit f5219c5

File tree

14 files changed

+15
-40
lines changed

14 files changed

+15
-40
lines changed

bin/a2l

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# @author Jerry Lee (oldratlee at gmail dot com)
1111
set -eEuo pipefail
1212

13-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
14-
PROG=$(basename -- "$0")
15-
readonly PROG
13+
readonly PROG=${0##*/}
1614
readonly PROG_VERSION='2.x-dev'
1715

1816
################################################################################

bin/ap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# @author Jerry Lee (oldratlee at gmail dot com)
1313
set -eEuo pipefail
1414

15-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
16-
PROG=$(basename -- "$0")
17-
readonly PROG
15+
readonly PROG=${0##*/}
1816
readonly PROG_VERSION='2.x-dev'
1917

2018
################################################################################

bin/c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
# var2=$(echo value1)
2727
set -eEuo pipefail
2828

29-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
30-
PROG=$(basename -- "$0")
31-
readonly PROG
29+
readonly PROG=${0##*/}
3230
readonly PROG_VERSION='2.x-dev'
3331

3432
################################################################################

bin/coat

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
# @author Jerry Lee (oldratlee at gmail dot com)
1212
set -eEuo pipefail
1313

14-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
15-
PROG=$(basename -- "$0")
16-
readonly PROG
14+
readonly PROG=${0##*/}
1715
readonly PROG_VERSION='2.x-dev'
1816

1917
################################################################################

bin/cp-into-docker-run

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
# @author Jerry Lee (oldratlee at gmail dot com)
1010
set -eEuo pipefail
1111

12-
PROG=$(basename -- "$0")
13-
readonly PROG
12+
readonly PROG=${0##*/}
1413
readonly PROG_VERSION='2.x-dev'
1514

1615
################################################################################
@@ -207,8 +206,7 @@ if [ ! -f "$specified_run_command" ]; then
207206
run_command=$(which "$specified_run_command")
208207
fi
209208
run_command=$(portableReadLink "$run_command")
210-
run_command_base_name=$(basename -- "$run_command")
211-
readonly run_command run_command_base_name
209+
readonly run_command run_command_base_name=${run_command##*/}
212210

213211
run_timestamp=$(date "+%Y%m%d_%H%M%S")
214212
readonly run_timestamp

bin/find-in-jars

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
# var2=$(echo value1)
3232
set -eEuo pipefail
3333

34-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
35-
PROG=$(basename -- "$0")
36-
readonly PROG
34+
readonly PROG=${0##*/}
3735
readonly PROG_VERSION='2.x-dev'
3836

3937
################################################################################

bin/rp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# @author Jerry Lee (oldratlee at gmail dot com)
1313
set -eEuo pipefail
1414

15-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
16-
PROG=$(basename -- "$0")
17-
readonly PROG
15+
readonly PROG=${0##*/}
1816
readonly PROG_VERSION='2.x-dev'
1917

2018
################################################################################

bin/show-busy-java-threads

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
# local var2
2626
# var2=$(echo value1)
2727

28-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
29-
PROG=$(basename -- "$0")
30-
readonly PROG
28+
readonly PROG=${0##*/}
3129
readonly PROG_VERSION='2.x-dev'
3230
# choosing between $0 and BASH_SOURCE
3331
# https://stackoverflow.com/a/35006505/922688

bin/taoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
# @author Jerry Lee (oldratlee at gmail dot com)
1212
set -eEuo pipefail
1313

14-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
15-
PROG=$(basename -- "$0")
16-
readonly PROG
14+
readonly PROG=${0##*/}
1715
readonly PROG_VERSION='2.x-dev'
1816

1917
################################################################################

bin/tcp-connection-state-counter

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# @author @sunuslee (sunuslee at gmail dot com)
1111
set -eEuo pipefail
1212

13-
# NOTE: DO NOT declare var PROG as readonly in ONE line!
14-
PROG=$(basename -- "$0")
15-
readonly PROG
13+
readonly PROG=${0##*/}
1614
readonly PROG_VERSION='2.x-dev'
1715

1816
################################################################################

0 commit comments

Comments
 (0)