From: Alejandro Colomar Date: Mon, 9 May 2022 12:35:57 +0000 (+0200) Subject: grepc: Optimize X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=febc343577b4e792560583530217ef325426b465;p=thirdparty%2Fman-pages.git grepc: Optimize Use 2 grep(1) filters instead of 1, to be able to filter better before the multiline pcregrep(1) filter, which is considerably slower. Signed-off-by: Alejandro Colomar --- diff --git a/bin/grepc b/bin/grepc index 7e76e9802..15c2b367c 100755 --- a/bin/grepc +++ b/bin/grepc @@ -11,9 +11,10 @@ function grepc_helper() { find . -type f \ | grep "$1" \ - | xargs grep -lP "$2" \ + | xargs grep -lPI "$2" \ + | xargs grep -lP "$3" \ | sort \ - | xargs pcregrep -Mn "$3" /dev/null \ + | xargs pcregrep -Mn "$4" /dev/null \ | sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n\n/'; } @@ -21,16 +22,18 @@ function grepc_helper() function grepc_macro_simple() { grepc_helper '\.[ch]$' \ - "define\s+$1\b[^(]" \ - "(?s)define\s+$1\b[^(].*?[^\\\\]$"; + "#\s*define\s+$1\b[^(]" \ + "." \ + "(?s)#\s*define\s+$1\b[^(].*?[^\\\\]$"; } function grepc_macro_func() { grepc_helper '\.[ch]$' \ - "define\s+$1\(" \ - "(?s)define\s+$1\(.*?[^\\\\]$"; + "#\s*define\s+$1\(" \ + "." \ + "(?s)#\s*define\s+$1\(.*?[^\\\\]$"; } @@ -44,6 +47,7 @@ function grepc_macro() function grepc_enum_constant() { grepc_helper '\.[ch]$' \ + "^enum\s" \ "^\s*$1\s*[,=]" \ "(?s)\benum\b\s*[\w\s[\]]*{[^}]*^\s*$1\s*[=,].*?^}.*?;"; } @@ -53,6 +57,7 @@ function grepc_func_decl() { grepc_helper '\.[ch]$' \ "\b$1\s*\(" \ + "." \ "(?s)^[\w[][\w\s(,)[:\]*]+\s+\**$1\s*\([\w\s(,)[\]*]+?(...)?\)[\w\s(,)[:\]]*;"; } @@ -61,6 +66,7 @@ function grepc_func_def() { grepc_helper '\.[ch]$' \ "\b$1\s*\(" \ + "." \ "(?s)^[\w[][\w\s(,)[:\]*]+\s+\**$1\s*\([\w\s(,)[\]*]+?(...)?\)\s*{.*?^}"; } @@ -75,7 +81,8 @@ function grepc_func() function grepc_linux_syscall_decl() { grepc_helper '\.[ch]$' \ - "\bsys_$1\s*\(" \ + "^asmlinkage\s+[\w\s]+\**sys_$1\s*\(" \ + "." \ "(?s)^asmlinkage\s+[\w\s]+\**sys_$1\s*\(.*?\)"; } @@ -84,6 +91,7 @@ function grepc_linux_syscall_def() { grepc_helper '\.c$' \ "SYSCALL_DEFINE.\($1\b" \ + "." \ "(?s)^\w*SYSCALL_DEFINE.\($1\b.*?^}"; } @@ -111,6 +119,7 @@ function grepc_type_struct_union_enum() { grepc_helper '\.[ch]$' \ "\b(struct|union|enum)\s+$1\b" \ + "." \ "(?s)^(?!^typedef\b)([\w[][\w\s(,)[:\]*]+\s+)?\b(struct|union|enum)\s+$1\b\s*[\w\s[\]]*{.*?^}.*?;"; } @@ -118,6 +127,7 @@ function grepc_type_struct_union_enum() function grepc_type_typedef_simple() { grepc_helper '\.[ch]$' \ + "^typedef\s" \ "\b$1;" \ "(?s)^typedef\s+[^{};]+$1;"; } @@ -126,6 +136,7 @@ function grepc_type_typedef_simple() function grepc_type_typedef_struct_union_enum() { grepc_helper '\.[ch]$' \ + "^typedef\s[^;]+$" \ "^}\s*$1;" \ "(?s)^typedef\s(?:(?!^}).)*^}\s*$1;"; }