[PATCH 04/10] checkpatch: skip redundant build_types() rebuilds
From: Bart Van Assche
Date: Tue Dec 01 2026 - 17:54:34 EST
Call build_types() at the end of the per-file loop only when
@modifierListFile or @typeListFile is non-empty, and call build_types() in
possible() only when a new modifier or type is appended.
Avoid rebuilding the composite $Type, $NonptrType, and $Declare regular
expressions and invalidating Perl's cached patterns that interpolate them
when the per-file type and modifier lists have not changed.
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
scripts/checkpatch.pl | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4ca3ce0f4502..ffafef4cd4f1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1545,9 +1545,11 @@ for my $filename (@ARGV) {
@fixed_inserted = ();
@fixed_deleted = ();
$fixlinenr = -1;
- @modifierListFile = ();
- @typeListFile = ();
- build_types();
+ if (@modifierListFile || @typeListFile) {
+ @modifierListFile = ();
+ @typeListFile = ();
+ build_types();
+ }
$file = $oldfile if ($is_git_file);
}
@@ -2508,6 +2510,7 @@ sub possible {
# Check for modifiers.
$possible =~ s/\s*$Storage\s*//g;
$possible =~ s/\s*$Sparse\s*//g;
+ my $types_changed = 0;
if ($possible =~ /^\s*$/) {
} elsif ($possible =~ /\s/) {
@@ -2516,14 +2519,16 @@ sub possible {
if ($modifier !~ $notPermitted) {
warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
push(@modifierListFile, $modifier);
+ $types_changed = 1;
}
}
} else {
warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
push(@typeListFile, $possible);
+ $types_changed = 1;
}
- build_types();
+ build_types() if ($types_changed);
} else {
warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
}