Commit 1b5539b1 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: reduce runtime/cpu time used

There are some cases where checkpatch can take a long time to complete.
Reduce the likelihood of this long run-time by adding a new test for lines
with and without comments and eliminating checks on lines with only
comments.

This reduces the number of "ctx_statement_block" calls, and also the
number of tests of $stat, which is now undefined for these blank lines.

One test in particular, the "check for switch/default statements without a
break", could take an extremely long time to parse as it tries to skip
interleaving comments within the ctx_statement_block/$stat and that could
be done multiple times unnecessarily.

A small test case taken from cfg80211.h before this patch would take
1000's of seconds to run, now it's just a couple seconds.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b34c648b
...@@ -1678,6 +1678,8 @@ sub process { ...@@ -1678,6 +1678,8 @@ sub process {
$linenr = 0; $linenr = 0;
foreach my $line (@lines) { foreach my $line (@lines) {
$linenr++; $linenr++;
my $sline = $line; #copy of $line
$sline =~ s/$;/ /g; #with comments as spaces
my $rawline = $rawlines[$linenr - 1]; my $rawline = $rawlines[$linenr - 1];
...@@ -2194,7 +2196,7 @@ sub process { ...@@ -2194,7 +2196,7 @@ sub process {
$realline_next); $realline_next);
#print "LINE<$line>\n"; #print "LINE<$line>\n";
if ($linenr >= $suppress_statement && if ($linenr >= $suppress_statement &&
$realcnt && $line =~ /.\s*\S/) { $realcnt && $sline =~ /.\s*\S/) {
($stat, $cond, $line_nr_next, $remain_next, $off_next) = ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
ctx_statement_block($linenr, $realcnt, 0); ctx_statement_block($linenr, $realcnt, 0);
$stat =~ s/\n./\n /g; $stat =~ s/\n./\n /g;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment