Skip to content

Commit

Permalink
perf(bash-v2): short-circuit descriptionless candidate lists
Browse files Browse the repository at this point in the history
If the list of candidates has no descriptions, short circuit all the
description processing logic, basically just do a `compgen -W` for the
whole list and be done with it.

We could conceivably do some optimizations like this and more when
generating the completions with `--no-descriptions`, but this way the
improvements are available also to completions generated with
descriptions enabled when they are invoked for completion cases that
produce no descriptions.
  • Loading branch information
scop committed Apr 30, 2022
1 parent 4f0facb commit db7eb2f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bash_completionsV2.go
Expand Up @@ -176,6 +176,14 @@ __%[1]s_handle_completion_types() {
__%[1]s_handle_standard_completion_case() {
local tab=$'\t' comp
# Short circuit to optimize if we don't have descriptions
if [[ $out != *$tab* ]]; then
while IFS='' read -r comp; do
COMPREPLY+=("$comp")
done < <(IFS=$'\n' compgen -W "$out" -- "$cur")
return 0
fi
local longest=0
# Look for the longest completion so that we can format things nicely
while IFS='' read -r comp; do
Expand Down

0 comments on commit db7eb2f

Please sign in to comment.