commit: f808b7d878041dbba66418e6b9ee0b1567c13471
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Jul 24 15:24:47 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 30 07:30:31 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=f808b7d8
60bash-completion: refrain from using has() for better performance
Rather than use has(), define associative arrays to keep track of the
seen completions and file basenames. Also, correct the broken array
length checks.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/install-qa-check.d/60bash-completion | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/bin/install-qa-check.d/60bash-completion
b/bin/install-qa-check.d/60bash-completion
index d3cb52d1c1..815ea55763 100644
--- a/bin/install-qa-check.d/60bash-completion
+++ b/bin/install-qa-check.d/60bash-completion
@@ -54,10 +54,9 @@ bashcomp_check() {
_have ${1} && have=yes
}
- local f c completions
- local all_compls=()
- local all_files=()
- local qa_warnings=()
+ local -A seen_completion seen_file
+ local -a completions qa_warnings
+ local f c
for f in "${instcompdir}"/*; do
# ignore directories and other non-files
@@ -76,7 +75,7 @@ bashcomp_check() {
unset 'completions[0]'
fi
- if [[ -z ${completions[@]} ]]; then
+ if (( ! ${#completions[@]} )); then
continue
fi
@@ -86,28 +85,28 @@ bashcomp_check() {
"${f##*/}: absolute paths can
not be used for completions (on '${c}')."
)
else
- all_compls+=( "${c}" )
+ seen_completion[$c]=1
fi
done
- if ! has "${f##*/}" "${all_compls[@]}"; then
+ if [[ ! ${seen_completion[${f##*/}]} ]]; then
qa_warnings+=(
"${f##*/}: incorrect name, no
completions for '${f##*/}' command defined."
)
fi
- all_files+=( "${f##*/}" )
+ seen_file[${f##*/}]=1
done
- for c in "${all_compls[@]}"; do
- if ! has "${c}" "${all_files[@]}"; then
+ for c in "${!seen_completion[@]}"; do
+ if [[ ! ${seen_file[$c]} ]]; then
qa_warnings+=(
"${c}: missing alias (symlink) for
completed command."
)
fi
done
- if [[ -n ${qa_warnings[@]} ]]; then
+ if (( ${#qa_warnings[@]} )); then
eqawarn "QA Notice: Problems with installed bash
completions were found:"
eqawarn
for c in "${qa_warnings[@]}"; do