Skip to content
Myr

perf: Loop over the bash variable directly instead of starting subprocesses. (#2333)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Today, the loop is printing the completions one value per line and then reading one line to a variable. We can just skip the whole IO rigamarole by looping over the completions directly.

authored by Jeffrey Faer · committed by GitHub · parent 88b30ab · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • other:+2 added−2 removed

1 file+2 added−2 removed

modified:bash_completionsV2.go+2 added-2 removed
324 unmodified lines
325326 local longest=0327 local compline328 # Look for the longest completion so that we can format things nicely329 while IFS='' read -r compline; do329 for compline in "${completions[@]}"; do330 [[ -z $compline ]] && continue331332 # Before checking if the completion matches what the user typed,333 # we need to strip any description and escape the completion to handle special
17 unmodified lines
351 comp=${compline%%%%$tab*}352 if ((${#comp}>longest)); then353 longest=${#comp}354 fi355 done < <(printf "%%s\n" "${completions[@]}")355 done356357 # If there is a single completion left, remove the description text and escape any special characters358 if ((${#COMPREPLY[*]} == 1)); then359 __%[1]s_debug "COMPREPLY[0]: ${COMPREPLY[0]}"
125 unmodified lines