perf: replace cat calls with echo in print_shell_function()

echo is a bash built-in, and thus you don't need to launch a new
process for something as simple as writing to stdout.
Saves about 2-3ms.
This commit is contained in:
Christian Fredrik Johnsen 2024-12-14 11:13:50 +01:00
parent 29dd360010
commit 63bd18d6d7

View File

@ -253,52 +253,40 @@ function print_shell_function() {
commands=(`pyenv-commands --sh`) commands=(`pyenv-commands --sh`)
case "$shell" in case "$shell" in
fish ) fish )
cat <<EOS echo "function pyenv
function pyenv
set command \$argv[1] set command \$argv[1]
set -e argv[1] set -e argv[1]
switch "\$command" switch \"\$command\"
case ${commands[*]} case ${commands[*]}
source (pyenv "sh-\$command" \$argv|psub) source (pyenv \"sh-\$command\" \$argv|psub)
case '*' case '*'
command pyenv "\$command" \$argv command pyenv \"\$command\" \$argv
end end
end end"
EOS
;; ;;
ksh | ksh93 | mksh ) ksh | ksh93 | mksh )
cat <<EOS echo "function pyenv {
function pyenv { typeset command=\$1"
typeset command
EOS
;; ;;
* ) * )
cat <<EOS echo "pyenv() {
pyenv() { local command=\$1"
local command
EOS
;; ;;
esac esac
if [ "$shell" != "fish" ]; then if [ "$shell" != "fish" ]; then
IFS="|" IFS="|"
cat <<EOS echo " [ \"\$#\" -gt 0 ] && shift
command="\${1:-}" case \"\$command\" in
if [ "\$#" -gt 0 ]; then
shift
fi
case "\$command" in
${commands[*]:-/}) ${commands[*]:-/})
eval "\$(pyenv "sh-\$command" "\$@")" eval \"\$(pyenv \"sh-\$command\" \"\$@\")\"
;; ;;
*) *)
command pyenv "\$command" "\$@" command pyenv \"\$command\" \"\$@\"
;; ;;
esac esac
} }"
EOS
fi fi
} }