diff options
author | Andy Whitcroft <apw@canonical.com> | 2012-01-10 18:10:01 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-10 19:30:50 -0500 |
commit | 3e469cdc08ac5d84b220f8fb76a090d158d5114f (patch) | |
tree | fc35a9ca8593ddd2bf0e07ceb2f39e83ff06ff4c /scripts/checkpatch.pl | |
parent | 89a883530fe79939384a6c6ed893c719762c7c9c (diff) |
checkpatch: optimise statement scanner when mid-statement
In the middle of a long definition or similar, there is no possibility of
finding a smaller sub-statement. Optimise this case by skipping statement
aquirey where there are no starts of statement (open brace '{' or
semi-colon ';'). We are likely to scan slightly more than needed still
but this is safest.
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b4390cf818da..618c0b5db0be 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -1373,6 +1373,7 @@ sub process { | |||
1373 | my %suppress_ifbraces; | 1373 | my %suppress_ifbraces; |
1374 | my %suppress_whiletrailers; | 1374 | my %suppress_whiletrailers; |
1375 | my %suppress_export; | 1375 | my %suppress_export; |
1376 | my $suppress_statement = 0; | ||
1376 | 1377 | ||
1377 | # Pre-scan the patch sanitizing the lines. | 1378 | # Pre-scan the patch sanitizing the lines. |
1378 | # Pre-scan the patch looking for any __setup documentation. | 1379 | # Pre-scan the patch looking for any __setup documentation. |
@@ -1482,6 +1483,7 @@ sub process { | |||
1482 | %suppress_ifbraces = (); | 1483 | %suppress_ifbraces = (); |
1483 | %suppress_whiletrailers = (); | 1484 | %suppress_whiletrailers = (); |
1484 | %suppress_export = (); | 1485 | %suppress_export = (); |
1486 | $suppress_statement = 0; | ||
1485 | next; | 1487 | next; |
1486 | 1488 | ||
1487 | # track the line number as we move through the hunk, note that | 1489 | # track the line number as we move through the hunk, note that |
@@ -1809,13 +1811,23 @@ sub process { | |||
1809 | # Check for potential 'bare' types | 1811 | # Check for potential 'bare' types |
1810 | my ($stat, $cond, $line_nr_next, $remain_next, $off_next, | 1812 | my ($stat, $cond, $line_nr_next, $remain_next, $off_next, |
1811 | $realline_next); | 1813 | $realline_next); |
1812 | if ($realcnt && $line =~ /.\s*\S/) { | 1814 | #print "LINE<$line>\n"; |
1815 | if ($linenr >= $suppress_statement && | ||
1816 | $realcnt && $line =~ /.\s*\S/) { | ||
1813 | ($stat, $cond, $line_nr_next, $remain_next, $off_next) = | 1817 | ($stat, $cond, $line_nr_next, $remain_next, $off_next) = |
1814 | ctx_statement_block($linenr, $realcnt, 0); | 1818 | ctx_statement_block($linenr, $realcnt, 0); |
1815 | $stat =~ s/\n./\n /g; | 1819 | $stat =~ s/\n./\n /g; |
1816 | $cond =~ s/\n./\n /g; | 1820 | $cond =~ s/\n./\n /g; |
1817 | 1821 | ||
1818 | #print "stat<$stat>\n"; | 1822 | #print "linenr<$linenr> <$stat>\n"; |
1823 | # If this statement has no statement boundaries within | ||
1824 | # it there is no point in retrying a statement scan | ||
1825 | # until we hit end of it. | ||
1826 | my $frag = $stat; $frag =~ s/;+\s*$//; | ||
1827 | if ($frag !~ /(?:{|;)/) { | ||
1828 | #print "skip<$line_nr_next>\n"; | ||
1829 | $suppress_statement = $line_nr_next; | ||
1830 | } | ||
1819 | 1831 | ||
1820 | # Find the real next line. | 1832 | # Find the real next line. |
1821 | $realline_next = $line_nr_next; | 1833 | $realline_next = $line_nr_next; |
@@ -1942,6 +1954,9 @@ sub process { | |||
1942 | 1954 | ||
1943 | # Check relative indent for conditionals and blocks. | 1955 | # Check relative indent for conditionals and blocks. |
1944 | if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { | 1956 | if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { |
1957 | ($stat, $cond, $line_nr_next, $remain_next, $off_next) = | ||
1958 | ctx_statement_block($linenr, $realcnt, 0) | ||
1959 | if (!defined $stat); | ||
1945 | my ($s, $c) = ($stat, $cond); | 1960 | my ($s, $c) = ($stat, $cond); |
1946 | 1961 | ||
1947 | substr($s, 0, length($c), ''); | 1962 | substr($s, 0, length($c), ''); |
@@ -2620,6 +2635,9 @@ sub process { | |||
2620 | # Check for illegal assignment in if conditional -- and check for trailing | 2635 | # Check for illegal assignment in if conditional -- and check for trailing |
2621 | # statements after the conditional. | 2636 | # statements after the conditional. |
2622 | if ($line =~ /do\s*(?!{)/) { | 2637 | if ($line =~ /do\s*(?!{)/) { |
2638 | ($stat, $cond, $line_nr_next, $remain_next, $off_next) = | ||
2639 | ctx_statement_block($linenr, $realcnt, 0) | ||
2640 | if (!defined $stat); | ||
2623 | my ($stat_next) = ctx_statement_block($line_nr_next, | 2641 | my ($stat_next) = ctx_statement_block($line_nr_next, |
2624 | $remain_next, $off_next); | 2642 | $remain_next, $off_next); |
2625 | $stat_next =~ s/\n./\n /g; | 2643 | $stat_next =~ s/\n./\n /g; |