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=1796165652; b=FCpUGgvQZzDIB/j51hlenlBq/+ceorv7lLiA84b4PeREX7Pnk01AfOIVVlSrhT+6yQvM /Fjz5b81aXVCOBMqI47n387C1stf9OQ2pJO3x5D6Zc9rkJv7/JnibGY6WF72Suvub1umZ ZAxcNU4Nuo6GQTe9ZAFwZFQ9WByFjiVJb01W56fJ5DTMMMT6rPXJ3nrlz9/U2AJC9cIIs ob1UQ150yWv3nq8/77/ScJDzGmB9sTlBJERrdXVS6PtRlhnhj+xL/h4ix0PsxrpwzSlSQ 4qbaqL0KjXvyj5e8uH3i6raAydHjXTIWP649HuQqwKovYqZ9wzLPTQNqAOF/awu6nvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796165652; 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=qxczukeRmIHUTCRZWyB1uxx8Bxgzcu6U2wtWE3DU+88=; b=M7/r2zKv2wqdrcJy7mVqjvQC6UA+A5TGxoY0/dFY+kpww5Sy0tUXDRkEhd0nRkWFj/kP wc9GM6vdfCarruk0cTmV5/MCXNuaWtyU88dYUKNJLmg3ZTaA3zfaBhlAiMBOyArDchdgA n954CM5nQNZrj7MPygpSdhLvKv6BVbmki+v88lbTZpT+U8X484HPhBLghm8aqcmYx1sjd K6Ux+2eK03MHhl5n3a6ils01T6wqdBWLrLh9pT0oYquiiOJqfpmInbdocxm0THaeEWw1x Tqiu7BDu2YquhChv3FyHgm8Lk2T+GDLYxk0g4Rgn7yDIi3K3lAr2NS6PbevO6TTWQ8w== 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=kNwSs3Wp; 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 0DB4A606A6A3 for ; Tue, 1 Dec 2026 22:54:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0DB4A606A6A3 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=kNwSs3Wp Received: from localhost (localhost [127.0.0.1]) by 011.lax.mailroute.net (Postfix) with ESMTP id 4jfGR75pbwz1XMYJN; Tue, 1 Dec 2026 22:54:11 +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=1796165649; x=1798757650; bh=qxczu keRmIHUTCRZWyB1uxx8Bxgzcu6U2wtWE3DU+88=; b=kNwSs3WpkCTEevZpBCkz1 BXrRKgNHk5XRueYkCBfSed9YpHyAYHAhE4eGGSPlD/7BK77zxIh4YEA1qSf0n3k6 eMJtEvW0/Of22dAUbUCIYMChGaePMwnf9wnyB6KSVa5CiC1S+qsY6uwhj0XxHHh+ gTcy8ItMpGvU1NuS+8FcGRwLUM9DqoF8ipnZS7jqhe+GHqUSfk8dWEcQojqNyvSH 1VkbTUsP7aQ8BdekNDHYVd/vr6d8BKXkolG/ne72DDvgTW8i1oYULgQn0EOWurRn 2AjJ5tmLdSOU9rtl+zKckQUoXLekGv8NF+xexpoYiRXW9K/eaYKKj0XqKl33idQX 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 2rhyjvrfdxnX; Tue, 1 Dec 2026 22:54:09 +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 4jfGR129NYz1XMYJg; Tue, 1 Dec 2026 22:54:05 +0000 (UTC) From: Bart Van Assche To: Joe Perches , Andy Whitcroft Cc: Andrew Morton , linux-kernel@vger.kernel.org, Bart Van Assche Subject: [PATCH 10/10] checkpatch: add fast paths to per-line character-scanning helpers Date: Tue, 1 Dec 2026 14:53:54 -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 Speed up three per-line character-scanning helpers: - sanitise_line(): return $line immediately when length($line) <=3D 1 or when $sanitise_quote is empty and substr($line, 1) contains none of '/', "'", '"', or '#'. - expand_tabs(): return $str immediately when index($str, "\t") < 0 and copy contiguous non-tab slices using index() and substr() instead of splitting into a per-character array. - get_raw_comment(): return '' immediately when index($line, "$;") < 0 an= d copy contiguous $;+ spans instead of iterating per character. Avoid per-character Perl loops on the common lines that lack quotes, comments, preprocessor directives, or tabs. Signed-off-by: Bart Van Assche --- scripts/checkpatch.pl | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b3854bc3ad6d..31723f178629 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1789,20 +1789,17 @@ sub which_conf { sub expand_tabs { my ($str) =3D @_; =20 + return $str if (index($str, "\t") < 0); + my $res =3D ''; - my $n =3D 0; - for my $c (split(//, $str)) { - if ($c eq "\t") { - $res .=3D ' '; - $n++; - for (; ($n % $tabsize) !=3D 0; $n++) { - $res .=3D ' '; - } - next; - } - $res .=3D $c; - $n++; + my $pos =3D 0; + my $idx; + while (($idx =3D index($str, "\t", $pos)) >=3D 0) { + $res .=3D substr($str, $pos, $idx - $pos); + $res .=3D ' ' x ($tabsize - (length($res) % $tabsize)); + $pos =3D $idx + 1; } + $res .=3D substr($str, $pos); =20 return $res; } @@ -1838,6 +1835,9 @@ sub sanitise_line_reset { sub sanitise_line { my ($line) =3D @_; =20 + return $line if (length($line) <=3D 1 || + ($sanitise_quote eq '' && substr($line, 1) !~ m{[/'"#]})); + my $res =3D ''; my $l =3D ''; =20 @@ -2928,12 +2928,12 @@ sub pos_last_openparen { =20 sub get_raw_comment { my ($line, $rawline) =3D @_; - my $comment =3D ''; =20 - for my $i (0 .. (length($line) - 1)) { - if (substr($line, $i, 1) eq "$;") { - $comment .=3D substr($rawline, $i, 1); - } + return '' if (index($line, "$;") < 0); + + my $comment =3D ''; + while ($line =3D~ /$;+/g) { + $comment .=3D substr($rawline, $-[0], $+[0] - $-[0]); } =20 return $comment;