Skip to content

Commit

Permalink
perf(__load_completion): reduce number of stat calls
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Apr 10, 2023
1 parent 6b8d4a5 commit 42b2c02
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2542,9 +2542,8 @@ __load_completion()
[[ $realcmd ]] && paths=("${realcmd%/*}") || paths=()
_comp_split -aF : paths "$PATH"
for dir in "${paths[@]%/}"; do
if [[ -d $dir && $dir == ?*/@(bin|sbin) ]]; then
[[ $dir == ?*/@(bin|sbin) ]] &&
dirs+=("${dir%/*}/share/bash-completion/completions")
fi
done
# 4) From XDG_DATA_DIRS or system dirs (e.g. /usr/share, /usr/local/share):
Expand All @@ -2557,10 +2556,14 @@ __load_completion()
# Look up and source
shift
local prefix
local i prefix compspec
for prefix in "" _; do # Regular from all dirs first, then fallbacks
for dir in "${dirs[@]}"; do
[[ -d $dir ]] || continue
for i in ${!dirs[*]}; do
dir=${dirs[i]}
if [[ ! -d $dir ]]; then
unset -v 'dirs[i]'
continue
fi
for compfile in "$prefix$cmdname" "$prefix$cmdname.bash"; do
compfile="$dir/$compfile"
# Avoid trying to source dirs as long as we support bash < 4.3
Expand Down

0 comments on commit 42b2c02

Please sign in to comment.