From patchwork Tue Oct 8 07:44:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 98480 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A324C38650D5 for ; Tue, 8 Oct 2024 07:44:46 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 64F2A386181E for ; Tue, 8 Oct 2024 07:44:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64F2A386181E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 64F2A386181E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728373451; cv=none; b=BwKIolFg6UBDO7IshCmJnip/Bag+vyF01gsEbdQ/pwEiO2bMIfMIzbJfQjViwrsUPSBauT6KNGAQbsGswFWm8tTvBU26sTQjnObQJsfKit7W2cRK8s2P/PlJ7xuLUxCETNpMVkn66eWk0VxtAc8Es9V/Spo3Rf9gjkXBYpbhBzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728373451; c=relaxed/simple; bh=az9O5JPQE9PkG4e7EnnSqFdGtsJNg6KnwcYVOhmRow8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=F/l6DNyd+EQvM/3KS0/qRf9GUPnYOmhI2r/Gp3c0xUhGEcWknChL0ZOG2jEHQr5Be3KiFA/RTVu9Vr49st5fJyydJsUT8e2OUA7bBOJ6I4rv5sdJL/KRTsWQLeJ7NI04LW4INezBrKleGcMZz7UfmcRUJaGJ4kkYxQZrtlwZtnc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 699EB219A5 for ; Tue, 8 Oct 2024 07:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728373448; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WLtG8xVrZU1aSdzauS7aOOkbPLaOaooL8Jk4jaZ3cRM=; b=gDHsn5mwTmfBFy2czR2G77mDgOmXLn9lfTRm2vbN0Miwk77p+nM99kvdnEPqxNWbm6Wk2a 5Gd/1ANLo2MGm4VYn3VuqvhyFAc8P+62sE/gniHyZJy21VVN/uDIqAGcXDTC0AaciYvaBq EWaK78REWE6gim4rMIZRd1yN+eSicdc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728373448; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WLtG8xVrZU1aSdzauS7aOOkbPLaOaooL8Jk4jaZ3cRM=; b=UeP2KkAGuvchWIbPMp1AcdrQZDAy1itlSKkpCVM7g2F1wHSwKQ+gG6CCT1UQRY50MYbY1l AbXhE7jXRRO145CA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728373448; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WLtG8xVrZU1aSdzauS7aOOkbPLaOaooL8Jk4jaZ3cRM=; b=gDHsn5mwTmfBFy2czR2G77mDgOmXLn9lfTRm2vbN0Miwk77p+nM99kvdnEPqxNWbm6Wk2a 5Gd/1ANLo2MGm4VYn3VuqvhyFAc8P+62sE/gniHyZJy21VVN/uDIqAGcXDTC0AaciYvaBq EWaK78REWE6gim4rMIZRd1yN+eSicdc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728373448; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WLtG8xVrZU1aSdzauS7aOOkbPLaOaooL8Jk4jaZ3cRM=; b=UeP2KkAGuvchWIbPMp1AcdrQZDAy1itlSKkpCVM7g2F1wHSwKQ+gG6CCT1UQRY50MYbY1l AbXhE7jXRRO145CA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4D89513A6E for ; Tue, 8 Oct 2024 07:44:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id +N52EcjiBGciFAAAD6G6ig (envelope-from ) for ; Tue, 08 Oct 2024 07:44:08 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 2/3] [gdb/contrib] Speed up spellcheck.sh --check Date: Tue, 8 Oct 2024 09:44:01 +0200 Message-Id: <20241008074402.10374-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20241008074402.10374-1-tdevries@suse.de> References: <20241008074402.10374-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org 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(-) 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 \