]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
src/bin/grepc_c: Split grepc_c_body_() and grepc_c_u_body_()
authorAlejandro Colomar <alx@kernel.org>
Thu, 6 Nov 2025 00:17:17 +0000 (01:17 +0100)
committerAlejandro Colomar <alx@kernel.org>
Thu, 6 Nov 2025 00:43:10 +0000 (01:43 +0100)
grepc_c_u_body_() consumes a lot of resources unnecessarily.
This is especially true within grepc_c_t_td_braced(), which was crashing
with relatively small code.  The reason is that grepc_c_t_td_braced()
searches for code where the identifier is last, so it needs to store
a lot of code just in case.  For that, an optimized grepc_c_body_() is
more appropriate.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/bin/grepc_c

index 2bda6978eefd79eeedb26fffd514d4b8c4615aa6..24a15e80debcc303d65cfb95fc51408e655d3c10 100755 (executable)
@@ -114,7 +114,8 @@ grepc_c_f_params_()     { printf '%s' '\s*(?<params>\((?:[\w\s,;[\]*\?:+-]|(?&pa
 grepc_c_f_decl_()       { grepc_c_f_return_;
                           printf '%s' '\(?'"$1"'\)?';
                           grepc_c_f_params_; }
-grepc_c_body_()         { printf '%s' '[ \t]*\n*(?<space>[ \t]*){(?:(?!^\k<space>?}).)*'"$1"'.*?^\k<space>}'; }
+grepc_c_body_()         { printf '%s' '[ \t]*\n*(?<space>[ \t]*){.*?^\k<space>}'; }
+grepc_c_u_body_()       { printf '%s' '[ \t]*\n*(?<space>[ \t]*){(?:(?!^\k<space>?}).)*'"$1"'.*?^\k<space>}'; }
 grepc_c_fld_decl_()     { printf '%s' '(?s)^(COMPAT_)?SYSCALL_DEFINE.\('"$1"'\b[\w\s,;[\]*\?:+-]*\)'; }
 grepc_c_m_decl_()       { printf '%s' '(?s)^[ \t]*#\s*define\s[\s\\]*'"$1"'\b'; }
 grepc_c_mf_decl_()      { grepc_c_m_decl_ "$1";
@@ -125,12 +126,12 @@ grepc_c_m_repl_()       { printf '%s' '(?:(?![^\\]$).)*'"$1"'.*?(?<!\\)$'; }
 
 
 grepc_c_e()             { grepc_c_e_decl_;
-                          grepc_c_body_ '^[ \t]*'"$1"'\b\s*[=,]';
+                          grepc_c_u_body_ '^[ \t]*'"$1"'\b\s*[=,]';
                           echo '[^;]*;'; }
 grepc_c_fp()            { grepc_c_f_decl_ "$1";
                           echo '(?:[\w\s\(,\)[\]]|::)*;'; }
 grepc_c_fd()            { grepc_c_f_decl_ "$1";
-                          grepc_c_body_ '';
+                          grepc_c_body_;
                           echo; }
 grepc_c_fgd_libm()      { grepc_c_fd "M_DECL_FUNC \(__$1\)"; }
 grepc_c_fgd_libio()     { grepc_c_fd "_IO_$1"; }
@@ -138,7 +139,7 @@ grepc_c_fgp_libio()     { grepc_c_fp "_IO_$1"; }
 grepc_c_fgp()           { grepc_c_fgp_libio "$1"; }
 grepc_c_flp()           { grepc_c_fp "(?:compat_)?sys_$1"; }
 grepc_c_fld()           { grepc_c_fld_decl_ "$1";
-                          grepc_c_body_ '';
+                          grepc_c_body_;
                           echo; }
 grepc_c_mf()            { grepc_c_mf_decl_ "$1";
                           grepc_c_m_repl_ '';
@@ -147,21 +148,21 @@ grepc_c_mo()            { grepc_c_mo_decl_ "$1";
                           grepc_c_m_repl_ '';
                           echo; }
 grepc_c_t_braced()      { printf '%s' '(?s)^([\w[]([\w\s\(,\)[\]*]|::)*[\w\s\)*\]]\s+)?\b(struct|union|enum)\b([\w \t[\]]|::)+\b'"$1"'\b';
-                          grepc_c_body_ '';
+                          grepc_c_body_;
                           echo '[^;]*;'; }
 grepc_c_t_td_simple()   { echo '(?s)^[ \t]*typedef\s+[^{};]+\b'"$1"';'; }
 grepc_c_t_td_braced()   { printf '%s' '(?s)^[ \t]*typedef\s+(struct|union|enum)\b(?:(?!\W'"$1"'\W)([\w \t[\]]|::))*';
-                          grepc_c_body_ '';
+                          grepc_c_body_;
                           echo '\s*'"$1"'(\[[\w\(,\)]\])*;'; }
 grepc_c_t_td_func()     { echo '(?s)^[ \t]*typedef\s+[^{};]+\(\**'"$1"'\)\s*\([^{};]+;'; }
 grepc_c_ue()            { grepc_c_e_decl_;
-                          grepc_c_body_ "$1";
+                          grepc_c_u_body_ "$1";
                           echo '[^;]*;'; }
 grepc_c_uf_def()        { grepc_c_f_decl_ '\w+';
-                          grepc_c_body_ "$1";
+                          grepc_c_u_body_ "$1";
                           echo; }
 grepc_c_uf_linux_def()  { grepc_c_fld_decl_ '\w+';
-                          grepc_c_body_ "$1";
+                          grepc_c_u_body_ "$1";
                           echo; }
 grepc_c_umf()           { grepc_c_mf_decl_ '\w+'
                           grepc_c_m_repl_ "$1";
@@ -170,11 +171,11 @@ grepc_c_umo()           { grepc_c_mo_decl_ '\w+'
                           grepc_c_m_repl_ "$1";
                           echo; }
 grepc_c_ut_su()         { printf '%s' '(?s)^(?!^[ \t]*typedef\b)([\w[]([\w\s\(,\)[\]*]|::)*[\w\s\)*\]]\s+)?\b(struct|union)\b([\w \t[\]]|::)*\w+';
-                          grepc_c_body_ "$1";
+                          grepc_c_u_body_ "$1";
                           echo '[^;]*;'; }
 grepc_c_ut_td_simple()  { echo '(?s)^[ \t]*typedef\s+[^{};]*'"$1"'[^{};]+;'; }
 grepc_c_ut_td_su()      { printf '%s' '(?s)^[ \t]*typedef\s+(struct|union)\b([\w \t[\]]|::)*';
-                          grepc_c_body_ "$1";
+                          grepc_c_u_body_ "$1";
                           echo '[^;]*;'; }