mirror of
https://github.com/spf13/cobra
synced 2025-05-05 04:47:22 +00:00
perf(bash-v2): short-circuit descriptionless candidate lists
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` in Go code, by omitting some parts we know won't be needed, or doing some things differently. But doing it this way in bash, the improvements are available also to completions generated with descriptions enabled when they are invoked for completion cases that produce no descriptions. The result after this for descriptionless entries seems fast enough so it seems there's no immediate need to look into doing that.
This commit is contained in:
parent
4f0facbcee
commit
ebdfdf3087
1 changed files with 8 additions and 0 deletions
|
@ -176,6 +176,14 @@ __%[1]s_handle_completion_types() {
|
||||||
__%[1]s_handle_standard_completion_case() {
|
__%[1]s_handle_standard_completion_case() {
|
||||||
local tab=$'\t' comp
|
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
|
local longest=0
|
||||||
# Look for the longest completion so that we can format things nicely
|
# Look for the longest completion so that we can format things nicely
|
||||||
while IFS='' read -r comp; do
|
while IFS='' read -r comp; do
|
||||||
|
|
Loading…
Add table
Reference in a new issue