aboutsummaryrefslogtreecommitdiff
path: root/gdb/contrib
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-10-21 15:07:02 +0200
committerTom de Vries <tdevries@suse.de>2024-10-21 15:07:02 +0200
commit6c80e57caaded430c37a10198a4d6ff9bba92bd8 (patch)
tree429243119dc07cbf8153d9457a1c6f78d4d6a41c /gdb/contrib
parent84fbbb5e6140791dbb60f3897c5bac5e9c173780 (diff)
downloadbinutils-6c80e57caaded430c37a10198a4d6ff9bba92bd8.zip
binutils-6c80e57caaded430c37a10198a4d6ff9bba92bd8.tar.gz
binutils-6c80e57caaded430c37a10198a4d6ff9bba92bd8.tar.bz2
[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.
Diffstat (limited to 'gdb/contrib')
-rwxr-xr-xgdb/contrib/spellcheck.sh49
1 files changed, 34 insertions, 15 deletions
diff --git a/gdb/contrib/spellcheck.sh b/gdb/contrib/spellcheck.sh
index 3188734..08c745a 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 \