From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=199.89.1.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796165653; b=pIAFKr7vsHTJCWqe69XoZuKAg22jqYjhXjiUNXbjS3DWqLZXj8jRMRGqdtEO1fYVEWvC ZXJhLmGO63hApWPcEfNnLy5uLaEA9OKNnNzWvCCaWy0UKyL1K/qeqrQf08crJYBjAOlFA JIzcLVgpl4TRMY6lbNvp3tQaPR9JqdS+WbtEeJzqhZQ7CTfla8n2UmaoK8f2jGmMq08dj 7liySzmTpuReHud5y7omKPYAO7lvhHTwEol8zqWDd4+lL/u8RtftqdMLDkK/0LMENz1wc C47XxvLc2VU+XLatuN/m2odfxe7Cf6TcVqa5evy+g/EMGjTi39mXUB6b55FBgfvfFvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796165653; h=DMARC-Filter:Received:DKIM-Signature:X-Virus-Scanned:Received: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=iU2+uX1Lmu0OIfYqlJbuPkEncqKYLk/gNjtslFun6K4=; b=HaKSaEtKSug7xc7Cl303vtYt1Zi/59na5hX2WNxmmmEx+KQ1hkDzFTHOIqyQ0jRkvdhx x3OrdFiTDjpuTQJPESzYlkYt1NSWhL2FTVAUpXYSVjUap3l12ScMwvupkobS7H84b2tQE yQ4MWWMLkq0IHIQ8EN5f9ICtvSo7UC82KRJgoAzIVbtMkvqwV1cDLNAanw4D9oUXGeLqY CzzTmE57zJUUscnak2ED8CHCZcD3FUw/9RVWqXUo8Vd/Urkn1fOaZBsdcLaEMKtHovFsW +3ZQUkmORz5OI1Ax2YPAGl/hSD0boMh0JcGOs0j5NvtsmDZLgKV9l95M53irXYXYUZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=aN9vTGMq; arc=none smtp.remote-ip=199.89.1.14 Received: from 011.lax.mailroute.net (011.lax.mailroute.net [199.89.1.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4168606A33C for ; Tue, 1 Dec 2026 22:54:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D4168606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=aN9vTGMq Received: from localhost (localhost [127.0.0.1]) by 011.lax.mailroute.net (Postfix) with ESMTP id 4jfGR82vPJz1XMYJV; Tue, 1 Dec 2026 22:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1796165647; x=1798757648; bh=iU2+u X1Lmu0OIfYqlJbuPkEncqKYLk/gNjtslFun6K4=; b=aN9vTGMqjiPbKyBQIeYzL oY8QGn4bLow1K3lv0oM96ebfiT1OUNnMGYVHn1zL6JoPsWiuUvpH9LCSRYdFS5oW 4dGy7K7sjn4Lqv8377c8kCzdAT9fYMyMyBc/ju3Qv9f470zlmvpeJ+oPhitc/2hp YA9kbqBRWBQKHlxzbVwf0zw8mav1AxySw5hjEAkemOZSolfgZl4nTche80WhlxKh pkWyRWQZHHYvPUmDDOxQ7SoPDNzXP2nt8KxHIV4xen51oe3o1aL+d+/OlSVAw7qH NQ1bK/fmBZiyv8tO6yLnMoY8X6qU5zcE6wZujG7hDD8669X+cs0B25FIwRFBuYNG w== X-Virus-Scanned: by MailRoute Received: from 011.lax.mailroute.net ([127.0.0.1]) by localhost (011.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 2Gb5YQYGNRvd; Tue, 1 Dec 2026 22:54:07 +0000 (UTC) Received: from bvanassche.c.googlers.com.com (57.237.82.34.bc.googleusercontent.com [34.82.237.57]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 011.lax.mailroute.net (Postfix) with ESMTPSA id 4jfGR036kdz1XMYJW; Tue, 1 Dec 2026 22:54:04 +0000 (UTC) From: Bart Van Assche To: Joe Perches , Andy Whitcroft Cc: Andrew Morton , linux-kernel@vger.kernel.org, Bart Van Assche Subject: [PATCH 07/10] checkpatch: use hash lookups for single-word spelling checks Date: Tue, 1 Dec 2026 14:53:51 -0800 Message-ID: X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Split %spelling_fix entries at startup into %spelling_fix_word for single tokens matching /^[\w\-'`]+$/ and lazily compiled multi-word regexes ($misspellings_multi_re and $misspellings_multi_has_re) for the remaining phrases instead of joining all entries into one alternation regex. Gate the TYPO_SPELLING check on (!$file || $check) and show_type("TYPO_SPELLING"), skip decode("utf8", $rawline) for pure-ASCII lines unless a multi-word entry contains a raw 0xDF byte (which only case-folds to "ss" in UTF-8 flagged strings), and preserve left-to-right report ordering and consumed trailing-delimiter semantics via $min_start =3D $end + 2. Avoid running a ~1,800 branch alternation regex (or tens of thousands of branches with --codespell) on every added and commit-log line, and skip spelling scans under -f when CHECK messages are disabled. Signed-off-by: Bart Van Assche --- scripts/checkpatch.pl | 93 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 6 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 64c965c84d7d..3eb2ac2c7a9b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -965,9 +965,15 @@ our $allowed_asm_includes =3D qr{(?x: )}; # memory.h: ARM has a custom one =20 -# Load common spelling mistakes and build regular expression list. +# Load common spelling mistakes and build lookup table / multi-word rege= x. my $misspellings; my %spelling_fix; +my %spelling_fix_word; +my $misspellings_multi_joined; +my $misspellings_multi_has_df =3D 0; +my $misspellings_multi_re; +my $misspellings_multi_has_re; +my $misspellings_full_re; =20 if (open(my $spelling, '<', $spelling_file)) { while (<$spelling>) { @@ -1012,7 +1018,23 @@ if ($codespell) { } } =20 -$misspellings =3D join("|", sort keys %spelling_fix) if keys %spelling_f= ix; +if (keys %spelling_fix) { + $misspellings =3D 1; + my @multi =3D (); + foreach my $suspect (sort keys %spelling_fix) { + if ($suspect =3D~ /^[\w\-'`]+$/) { + $spelling_fix_word{lc($suspect)} =3D 1; + } else { + push(@multi, $suspect); + } + } + if (@multi) { + $misspellings_multi_joined =3D join("|", @multi); + # A raw (non-UTF-8) 0xDF byte case-folds to "ss" only when + # matched against a string with the UTF8 flag set. + $misspellings_multi_has_df =3D ($misspellings_multi_joined =3D~ /\xdf/= ); + } +} =20 sub read_words { my ($wordsRef, $file) =3D @_; @@ -3745,12 +3767,71 @@ sub process { =20 # Check for various typo / spelling mistakes if (defined($misspellings) && + (!$file || $check) && + show_type("TYPO_SPELLING") && ($in_commit_log || $line =3D~ /^(?:\+|Subject:)/i)) { - my $rawline_utf8 =3D decode("utf8", $rawline); - while ($rawline_utf8 =3D~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]= |$)/gi) { - my $typo =3D $1; + my $is_non_ascii =3D ($rawline =3D~ /[^\x00-\x7f]/); + my $rawline_utf8 =3D ($is_non_ascii || $misspellings_multi_has_df) ? + decode("utf8", $rawline) : $rawline; + my @typo_matches =3D (); + my $use_full =3D ($is_non_ascii && + $rawline_utf8 =3D~ /[\x{00df}\x{017f}\x{1e9e}\x{fb00}-\x{fb06}]/); + if (!$use_full && defined($misspellings_multi_joined) && + !defined($misspellings_multi_re)) { + $misspellings_multi_re =3D qr{(?:^|[^\w\-'`])($misspellings_multi_jo= ined)(?:[^\w\-'`]|$)}i; + } + if (!$use_full && defined($misspellings_multi_re) && + $rawline_utf8 =3D~ $misspellings_multi_re) { + if (!defined($misspellings_multi_has_re)) { + $misspellings_multi_has_re =3D qr{(?=3D(?:^|[^\w\-'`])($misspelling= s_multi_joined)(?:[^\w\-'`]|$))}i; + } + my @cands =3D (); + while ($rawline_utf8 =3D~ /([\w\-'`]+)/g) { + if (exists($spelling_fix_word{lc($1)})) { + push(@cands, [$-[1], $+[1], $1]); + } + } + while ($rawline_utf8 =3D~ /$misspellings_multi_has_re/g) { + push(@cands, [$-[1], $+[1], $1]); + } + @cands =3D sort { $a->[0] <=3D> $b->[0] } @cands; + for (my $i =3D 1; $i < @cands; $i++) { + if ($cands[$i]->[0] =3D=3D $cands[$i - 1]->[0]) { + $use_full =3D 1; + last; + } + } + if (!$use_full) { + my $min_start =3D 0; + foreach my $cand (@cands) { + next if ($cand->[0] < $min_start); + push(@typo_matches, $cand); + $min_start =3D $cand->[1] + 2; + } + } + } elsif (!$use_full) { + my $min_start =3D 0; + while ($rawline_utf8 =3D~ /([\w\-'`]+)/g) { + next if ($-[1] < $min_start); + if (exists($spelling_fix_word{lc($1)})) { + push(@typo_matches, [$-[1], $+[1], $1]); + $min_start =3D $+[1] + 2; + } + } + } + if ($use_full) { + if (!defined($misspellings_full_re)) { + my $all =3D join("|", sort keys %spelling_fix); + $misspellings_full_re =3D qr{(?:^|[^\w\-'`])($all)(?:[^\w\-'`]|$)}i= ; + } + while ($rawline_utf8 =3D~ /$misspellings_full_re/g) { + push(@typo_matches, [$-[1], $+[1], $1]); + } + } + foreach my $m (@typo_matches) { + my ($typo_start, $typo) =3D ($m->[0], $m->[2]); my $blank =3D copy_spacing($rawline_utf8); - my $ptr =3D substr($blank, 0, $-[1]) . "^" x length($typo); + my $ptr =3D substr($blank, 0, $typo_start) . "^" x length($typo); my $hereptr =3D "$hereline$ptr\n"; my $typo_fix =3D $spelling_fix{lc($typo)}; $typo_fix =3D ucfirst($typo_fix) if ($typo =3D~ /^[A-Z]/);