[2/3,gdb/contrib] Speed up spellcheck.sh --check
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
Commit Message
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.
---
gdb/contrib/spellcheck.sh | 49 +++++++++++++++++++++++++++------------
1 file changed, 34 insertions(+), 15 deletions(-)
Comments
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> Speed up gdb/contrib/shellcheck.sh by caching the grep pattern.
Tom> Without cached grep pattern:
Tom> ...
Tom> $ time ./gdb/contrib/spellcheck.sh --check gdb/gdb.c
Tom> real 0m2,750s
Tom> user 0m0,013s
Tom> sys 0m0,032s
Tom> ...
Tom> and with cached grep pattern:
Tom> ...
Tom> $ time ./gdb/contrib/spellcheck.sh --check gdb/gdb.c
Tom> real 0m0,192s
Tom> user 0m0,022s
Tom> sys 0m0,024s
Tom> ...
Tom> Tested on aarch64-linux.
Seems reasonable.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
@@ -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 \