mirror of
https://github.com/pyenv/pyenv.git
synced 2025-11-14 06:13:53 -05:00
Speed up realpath() with dynamically loaded C extension
On systems that support both C compiling and dynamic loading, we can speed up `realpath()` (where most time in rbenv is spent) by replacing it with a dynamically loaded bash builtin. When `make -C src` is called in the project's root, `libexec/rbenv-realpath.dylib` will be created. If it exists, rbenv will attempt to load it as a builtin command. If it fails, execution will fall back to the old `realpath()` shell function.
This commit is contained in:
@@ -19,6 +19,7 @@ if [ -z "$RBENV_COMMAND" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; then
|
||||
READLINK=$(type -p greadlink readlink | head -1)
|
||||
if [ -z "$READLINK" ]; then
|
||||
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
|
||||
@@ -42,13 +43,14 @@ realpath() {
|
||||
echo "$(pwd)/$name"
|
||||
cd "$cwd"
|
||||
}
|
||||
fi
|
||||
|
||||
IFS=: hook_paths=($RBENV_HOOK_PATH)
|
||||
|
||||
shopt -s nullglob
|
||||
for path in "${hook_paths[@]}"; do
|
||||
for script in "$path/$RBENV_COMMAND"/*.bash; do
|
||||
echo $(realpath $script)
|
||||
realpath "$script"
|
||||
done
|
||||
done
|
||||
shopt -u nullglob
|
||||
|
||||
Reference in New Issue
Block a user