From 8e5379ebe34b49b134ee7ab2165f419eb1f77050 Mon Sep 17 00:00:00 2001 From: Christian Fredrik Johnsen Date: Wed, 25 Dec 2024 12:37:34 +0100 Subject: [PATCH] perf: faster execution of build_conda_exclusion_list 1) Got rid of useless call to `cat`, much better to simply use sed with file as argument. 2) Got rid of `sort -u`. There is no need to sort the list. Additionally, the list `pyenv.d/rehash/conda.d/default.list` only has unique entries, and even if you have duplicate entries, the function will still work. --> No need for sort nor unique. 3) Further improvement is simple, save a cached cleaned-list-v1.0 in `conda.d` and simple read from that file instead of doing `sed`, which must be a more expensive operation than simply reading from file. --- pyenv.d/rehash/conda.bash | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyenv.d/rehash/conda.bash b/pyenv.d/rehash/conda.bash index 6f65d2b4..ab17ca13 100644 --- a/pyenv.d/rehash/conda.bash +++ b/pyenv.d/rehash/conda.bash @@ -18,13 +18,11 @@ if conda_exists; then # `conda_shim` to skip creating shims for those binaries. build_conda_exclusion_list() { shims=() - shopt -s nullglob - for shim in $(cat "${BASH_SOURCE%/*}/conda.d/"*".list" | sort -u | sed -e 's/#.*$//' | sed -e '/^[[:space:]]*$/d'); do + for shim in $(sed 's/#.*$//; /^[[:space:]]*$/d' "${BASH_SOURCE%/*}/conda.d/default.list"); do if [ -n "${shim##*/}" ]; then shims[${#shims[*]}]="${shim})return 0;;" fi done - shopt -u nullglob eval \ "conda_shim() { case \"\${1##*/}\" in