mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
rehash: use associative array to hold registered shims
"hyperfine pyenv-rehash" before on my bash 4.4: Time (mean ± σ): 172.8 ms ± 8.2 ms [User: 185.0 ms, System: 24.8 ms] Range (min … max): 164.2 ms … 198.4 ms 15 runs After: Time (mean ± σ): 113.8 ms ± 2.8 ms [User: 127.1 ms, System: 26.1 ms] Range (min … max): 108.0 ms … 117.6 ms 25 runs
This commit is contained in:
parent
b7efafe599
commit
a804887307
1 changed files with 53 additions and 25 deletions
|
@ -123,17 +123,19 @@ make_shims() {
|
|||
done
|
||||
}
|
||||
|
||||
registered_shims=" "
|
||||
if ((${BASH_VERSINFO[0]} > 3)); then
|
||||
|
||||
declare -A registered_shims
|
||||
|
||||
# Registers the name of a shim to be generated.
|
||||
register_shim() {
|
||||
registered_shims="${registered_shims}${1} "
|
||||
registered_shims["$1"]=1
|
||||
}
|
||||
|
||||
# Install all the shims registered via `make_shims` or `register_shim` directly.
|
||||
# Install all shims registered via `make_shims` or `register_shim` directly.
|
||||
install_registered_shims() {
|
||||
local shim file
|
||||
for shim in $registered_shims; do
|
||||
for shim in "${!registered_shims[@]}"; do
|
||||
file="${SHIM_PATH}/${shim}"
|
||||
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
|
||||
done
|
||||
|
@ -143,6 +145,31 @@ install_registered_shims() {
|
|||
# over the contents of the shims directory. Any file that is present
|
||||
# in the directory but has not been registered as a shim should be
|
||||
# removed.
|
||||
remove_stale_shims() {
|
||||
local shim
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
if [[ ! ${registered_shims["${shim##*/}"]} ]]; then
|
||||
rm -f "$shim"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
else # Same for bash < 4.
|
||||
|
||||
registered_shims=" "
|
||||
|
||||
register_shim() {
|
||||
registered_shims="${registered_shims}${1} "
|
||||
}
|
||||
|
||||
install_registered_shims() {
|
||||
local shim file
|
||||
for shim in $registered_shims; do
|
||||
file="${SHIM_PATH}/${shim}"
|
||||
[ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file"
|
||||
done
|
||||
}
|
||||
|
||||
remove_stale_shims() {
|
||||
local shim
|
||||
for shim in "$SHIM_PATH"/*; do
|
||||
|
@ -151,6 +178,7 @@ remove_stale_shims() {
|
|||
fi
|
||||
done
|
||||
}
|
||||
fi
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
|
|
Loading…
Reference in a new issue