mirror of
https://github.com/pyenv/pyenv.git
synced 2026-04-06 13:45:11 +09:00
versions: fast path for --bare --skip-aliases (#3411)
Skip sort, native extension probe, and per-symlink realpath when called with --bare --skip-aliases (the rehash case). Use readlink to distinguish internal aliases (relative target) from external installs (absolute target). In MacOS, speeds up rehash by 5.2 ms (7%) in empty environment, 55.9 ms (33%) in a regular environment (3 ver, 12 venvs, 320 bins), 93.7 ms (15%) in a large environment (6 ver, 60 venvs, 1466 bins)
This commit is contained in:
parent
aa2e8b8260
commit
23bcdebe18
@ -26,6 +26,29 @@ for arg; do
|
||||
esac
|
||||
done
|
||||
|
||||
# Fast path for --bare --skip-aliases: skip sort and full realpath resolution
|
||||
if [[ -n "$bare" && -n "$skip_aliases" ]]; then
|
||||
versions_dir="${PYENV_ROOT}/versions"
|
||||
if [ -d "$versions_dir" ]; then
|
||||
shopt -s dotglob nullglob
|
||||
for path in "$versions_dir"/*/; do
|
||||
path="${path%/}"
|
||||
if [ -L "$path" ]; then
|
||||
# Relative link = internal alias → skip; absolute = external → keep
|
||||
[[ "$(readlink "$path")" == /* ]] || continue
|
||||
fi
|
||||
echo "${path##*/}"
|
||||
if [[ -z "$skip_envs" ]]; then
|
||||
for env_path in "${path}/envs/"*; do
|
||||
[ -d "$env_path" ] && echo "${env_path#${versions_dir}/}"
|
||||
done
|
||||
fi
|
||||
done
|
||||
shopt -u dotglob nullglob
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
versions_dir="${PYENV_ROOT}/versions"
|
||||
|
||||
if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user