Skip to content

Commit

Permalink
perf: use ${var##} instead of basename 🎛️
Browse files Browse the repository at this point in the history
no subprocess fork, faster
  • Loading branch information
oldratlee committed Jan 29, 2024
1 parent 20520c1 commit bdd10c5
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 40 deletions.
4 changes: 1 addition & 3 deletions bin/a2l
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

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

################################################################################
Expand Down
4 changes: 1 addition & 3 deletions bin/ap
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

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

################################################################################
Expand Down
4 changes: 1 addition & 3 deletions bin/c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
# var2=$(echo value1)
set -eEuo pipefail

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

################################################################################
Expand Down
4 changes: 1 addition & 3 deletions bin/coat
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

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

################################################################################
Expand Down
6 changes: 2 additions & 4 deletions bin/cp-into-docker-run
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

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

################################################################################
Expand Down Expand Up @@ -207,8 +206,7 @@ if [ ! -f "$specified_run_command" ]; then
run_command=$(which "$specified_run_command")
fi
run_command=$(portableReadLink "$run_command")
run_command_base_name=$(basename -- "$run_command")
readonly run_command run_command_base_name
readonly run_command run_command_base_name=${run_command##*/}

run_timestamp=$(date "+%Y%m%d_%H%M%S")
readonly run_timestamp
Expand Down
4 changes: 1 addition & 3 deletions bin/find-in-jars
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
# var2=$(echo value1)
set -eEuo pipefail

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

################################################################################
Expand Down
4 changes: 1 addition & 3 deletions bin/rp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

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

################################################################################
Expand Down
4 changes: 1 addition & 3 deletions bin/show-busy-java-threads
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
# local var2
# var2=$(echo value1)

# NOTE: DO NOT declare var PROG as readonly in ONE line!
PROG=$(basename -- "$0")
readonly PROG
readonly PROG=${0##*/}
readonly PROG_VERSION='2.x-dev'
# choosing between $0 and BASH_SOURCE
# https://stackoverflow.com/a/35006505/922688
Expand Down
4 changes: 1 addition & 3 deletions bin/taoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# @author Jerry Lee (oldratlee at gmail dot com)
set -eEuo pipefail

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

################################################################################
Expand Down
4 changes: 1 addition & 3 deletions bin/tcp-connection-state-counter
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
# @author @sunuslee (sunuslee at gmail dot com)
set -eEuo pipefail

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

################################################################################
Expand Down
4 changes: 1 addition & 3 deletions bin/uq
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
# var2=$(echo value1)
set -eEuo pipefail

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

################################################################################
Expand Down
4 changes: 1 addition & 3 deletions bin/xpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
# var2=$(echo value1)
set -eEuo pipefail

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

################################################################################
Expand Down
3 changes: 1 addition & 2 deletions legacy-bin/cp-svn-url
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
# local var2
# var2=$(echo value1)

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

usage() {
Expand Down
2 changes: 1 addition & 1 deletion legacy-bin/svn-merge-stop-on-copy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# @author jiangjizhong(@jzwlqx)
# @author Jerry Lee (oldratlee at gmail dot com)

PROG="$(basename -- "$0")"
readonly PROG=${0##*/}

usage() {
cat <<EOF
Expand Down

0 comments on commit bdd10c5

Please sign in to comment.