Skip to content
Myr

perf(bash-v2): use backslash escape string expansion for tab (#1682)

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

Using a command substitution, i.e. a subshell, with `printf` is expensive for this purpose. For example `__*_format_comp_descriptions` is run once for each completion candidate; the expense adds up and shows when there are a lot of them.

authored by Ville Skyttä · committed by GitHub · parent d8184d3 · Browse files · 1 file+3 added−6 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+3 added−6 removed

  • other:+3 added−6 removed

1 file+3 added−6 removed

modified:bash_completionsV2.go+3 added-6 removed
152 unmodified lines
153 # Type: menu-complete/menu-complete-backward and insert-completions154 # If the user requested inserting one completion at a time, or all155 # completions at once on the command-line we must remove the descriptions.156 # https://github.com/spf13/cobra/issues/1508157 local tab comp158 tab=$(printf '\t')157 local tab=$'\t' comp158 while IFS='' read -r comp; do159 # Strip any description160 comp=${comp%%%%$tab*}161 # Only consider the completions that match
11 unmodified lines
173 esac174}175176__%[1]s_handle_standard_completion_case() {178 local tab comp179 tab=$(printf '\t')177 local tab=$'\t' comp178179 local longest=0180 # Look for the longest completion so that we can format things nicely181 while IFS='' read -r comp; do
46 unmodified lines
228}229230__%[1]s_format_comp_descriptions()231{234 local tab235 tab=$(printf '\t')232 local tab=$'\t'233 local comp="$1"234 local longest=$2235236 # Properly format the description string which follows a tab character if there is one
92 unmodified lines