lkml.org 
[lkml]   [2010]   [Feb]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] scripts/checkpatch.pl: Dramatically improve #define parse times
From
Date
On Mon, 2010-02-08 at 15:15 -0800, Andrew Morton wrote:
> This patch triggers lots of warnings:

Yeah, I've played with it a bit more but Andy Whitcroft
is better able to do something about this.

This is what I've come up with, which doesn't fail your
example and gives the same output as current on a bunch
of collected patches, but it only handles:
#define foo bar
not
#define foo (bar)
#define foo (bar * n)

Andy?

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3257d3d..940fe82 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -378,13 +378,13 @@ sub sanitise_line {
if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
$sanitise_quote = '*/';

- substr($res, $off, 2, "$;$;");
+ substr($res, $off, 2, " ");
$off++;
next;
}
if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
$sanitise_quote = '';
- substr($res, $off, 2, "$;$;");
+ substr($res, $off, 2, " ");
$off++;
next;
}
@@ -417,9 +417,9 @@ sub sanitise_line {

#print "c<$c> SQ<$sanitise_quote>\n";
if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
- substr($res, $off, 1, $;);
+ substr($res, $off, 1, ' ');
} elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
- substr($res, $off, 1, $;);
+ substr($res, $off, 1, ' ');
} elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
substr($res, $off, 1, 'X');
} else {
@@ -507,6 +507,12 @@ sub ctx_statement_block {
last;
}

+ # single line "#define foo" and "#define foo bar" at level 0 are complete
+ if ($level == 0 &&
+ ($remainder =~ /^\s*#\s*define\s+\w+\s*$/ || $remainder =~ /^\s*#\s*define\s+\w+\s+\w+\s*$/)) {
+ last;
+ }
+
# An else is really a conditional as long as its not else if
if ($level == 0 && $coff_set == 0 &&
(!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
@@ -2352,7 +2358,9 @@ sub process {
^\"|\"$
}x;
#print "REST<$rest> dstat<$dstat>\n";
- if ($rest ne '') {
+ if ($rest =~ /^\s*define\s+\w+\s*$/ || $rest =~ /^\s*define\s+\w+\s+\w+\s*$/) {
+ ;
+ } elsif ($rest ne '') {
if ($rest !~ /while\s*\(/ &&
$dstat !~ /$exceptions/)
{




\
 
 \ /
  Last update: 2010-02-09 02:45    [W:0.038 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site