From: Tom de Vries Date: Mon, 21 Oct 2024 13:07:02 +0000 (+0200) Subject: [gdb/contrib] Speed up spellcheck.sh --check X-Git-Tag: gdb-16-branchpoint~622 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6c80e57caaded430c37a10198a4d6ff9bba92bd8;p=thirdparty%2Fbinutils-gdb.git [gdb/contrib] Speed up spellcheck.sh --check Speed up gdb/contrib/shellcheck.sh by caching the grep pattern. Without cached grep pattern: ... $ time ./gdb/contrib/spellcheck.sh --check gdb/gdb.c real 0m2,750s user 0m0,013s sys 0m0,032s ... and with cached grep pattern: ... $ time ./gdb/contrib/spellcheck.sh --check gdb/gdb.c real 0m0,192s user 0m0,022s sys 0m0,024s ... Tested on aarch64-linux. --- diff --git a/gdb/contrib/spellcheck.sh b/gdb/contrib/spellcheck.sh index 3188734331c..08c745aa92d 100755 --- a/gdb/contrib/spellcheck.sh +++ b/gdb/contrib/spellcheck.sh @@ -20,12 +20,14 @@ # $ ./gdb/contrib/spellcheck.sh gdb* scriptdir=$(cd "$(dirname "$0")" || exit; pwd -P) +this_script=$scriptdir/$(basename "$0") url=https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines cache_dir=$scriptdir/../../.git cache_file=wikipedia-common-misspellings.txt dictionary=$cache_dir/$cache_file local_dictionary=$scriptdir/common-misspellings.txt +cache_file2=spell-check.pat1 # Separators: space, slash, tab, colon, comma. declare -a grep_separators @@ -191,21 +193,38 @@ parse_dictionary () find_files_matching_words () { - local pat - pat="" - for word in "${words[@]}"; do - if [ "$pat" = "" ]; then - pat="$word" - else - pat="$pat|$word" - fi - done - pat="($pat)" - - local sep - sep=$grep_separator - - pat="(^|$sep)$pat($sep|$)" + local cache_id + cache_id=$(cat "$local_dictionary" "$dictionary" "$this_script" \ + | md5sum \ + | awk '{print $1}') + + local patfile + patfile="$cache_dir/$cache_file2".$cache_id + + if [ -f "$patfile" ]; then + pat=$(cat "$patfile") + else + rm -f "$cache_dir/$cache_file2".* + + local pat + pat="" + for word in "${words[@]}"; do + if [ "$pat" = "" ]; then + pat="$word" + else + pat="$pat|$word" + fi + done + pat="($pat)" + + local sep + sep=$grep_separator + + pat="(^|$sep)$pat($sep|$)" + + echo "$pat" \ + > "$patfile" + fi grep -E \ -l \