Skip to content

Commit 5a85108

Browse files
committed
perf(tar): cache the parse result of GNU tar help
1 parent 281261a commit 5a85108

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

completions/tar

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ _comp_cmd_gtar__parse_help_line()
119119
done <<<"$1"
120120
}
121121

122+
# Cache of _comp_cmd_gtar__parse_help()
123+
_comp_cmd_gtar__parse_help__mut_cache=
124+
122125
# Parse the output of "tar --help" with GNU tar and store the parse results
123126
# into variables.
124127
#
@@ -131,8 +134,18 @@ _comp_cmd_gtar__parse_help_line()
131134
# @var[out] short_arg_opt
132135
# @var[out] short_arg_req
133136
# The parse results are returned in these variables.
137+
#
138+
# @var[in,out] _comp_cmd_gtar__parse_help__mut_cache
139+
# The parse results are cached in this global variable. If this variable
140+
# is non-empty, this variable is used to obtain the parse results instead
141+
# of parsing the output of "tar --help" again.
134142
_comp_cmd_gtar__parse_help()
135143
{
144+
if [[ $_comp_cmd_gtar__parse_help__mut_cache ]]; then
145+
eval -- "$_comp_cmd_gtar__parse_help__mut_cache"
146+
return
147+
fi
148+
136149
long_arg_none=""
137150
long_arg_opt=""
138151
long_arg_req=""
@@ -168,6 +181,16 @@ _comp_cmd_gtar__parse_help()
168181
$long_arg_none $long_arg_opt $long_arg_req"
169182

170183
short_opts="$short_arg_none$short_arg_opt$short_arg_req"
184+
185+
printf -v _comp_cmd_gtar__parse_help__mut_cache '%s=%q ' \
186+
long_opts "$long_opts" \
187+
short_opts "$short_opts" \
188+
long_arg_none "$long_arg_none" \
189+
long_arg_opt "$long_arg_opt" \
190+
long_arg_req "$long_arg_req" \
191+
short_arg_none "$short_arg_none" \
192+
short_arg_opt "$short_arg_opt" \
193+
short_arg_req "$short_arg_req"
171194
}
172195

173196
# Hack: parse --warning keywords from tar's error output

0 commit comments

Comments
 (0)