Speed up rehash process when there are many Ruby versions

On my system that has 25 versions under rbenv, this speeds up rehash
almost 3-fold:

- before: 391 ms
- after:  134 ms

This is achieved by removing duplicate names of executables before
registering them as shims. Since most Rubies will share a lot of the
same executable names ("ruby", "rake", "bundle", ...), this is a
considerable reduction in number of shims registered.
This commit is contained in:
Mislav Marohnić 2014-10-15 04:05:41 +02:00
parent a8df5d587c
commit 89d4e8a0e0

View file

@ -79,6 +79,14 @@ remove_outdated_shims() {
done done
} }
# List basenames of executables for every Ruby version
list_executable_names() {
local file
for file in "$RBENV_ROOT"/versions/*/bin/*; do
echo "${file##*/}"
done
}
# The basename of each argument passed to `make_shims` will be # The basename of each argument passed to `make_shims` will be
# registered for installation as a shim. In this way, plugins may call # registered for installation as a shim. In this way, plugins may call
# `make_shims` with a glob to register many shims at once. # `make_shims` with a glob to register many shims at once.
@ -136,7 +144,7 @@ shopt -s nullglob
# executables. # executables.
create_prototype_shim create_prototype_shim
remove_outdated_shims remove_outdated_shims
make_shims ../versions/*/bin/* make_shims $(list_executable_names | sort -u)
# Allow plugins to register shims. # Allow plugins to register shims.