Skip to content

Commit

Permalink
perf(bash-v2): read directly to COMPREPLY on descriptionless short ci…
Browse files Browse the repository at this point in the history
…rcuit (#1700)

Not that it'd really matter that much performancewise given the level we
are at for this case, but this change makes the short circuit roughly
twice as fast on my box as it was for the 1000 rounds done in
marckhouzam/cobra-completion-testing.

Perhaps more importantly, this makes the code arguably slightly cleaner.
  • Loading branch information
scop committed May 18, 2022
1 parent ffa8860 commit 5b11656
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions bash_completionsV2.go
Expand Up @@ -178,9 +178,7 @@ __%[1]s_handle_standard_completion_case() {
# 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")
IFS=$'\n' read -ra COMPREPLY -d '' < <(IFS=$'\n' compgen -W "$out" -- "$cur")
return 0
fi
Expand Down

0 comments on commit 5b11656

Please sign in to comment.