]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
bash_aliases: grep_*(): Optimize
authorAlejandro Colomar <alx.manpages@gmail.com>
Sun, 14 Nov 2021 13:54:24 +0000 (14:54 +0100)
committerAlejandro Colomar <alx.manpages@gmail.com>
Sun, 14 Nov 2021 13:54:26 +0000 (14:54 +0100)
Using grep first to reduce the files on which pcregrep is run
optimizes considerably the performance of these functions.

If a file doesn't contain the name of a function,
which can easily be checked with grep,
it won't possibly contain the function prototype or definition,
which is much slower to search,
since it implies multiline pcregrep search.

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
scripts/bash_aliases

index be0672595a29a9eb9f61a74ff51fe1508846cc9f..e9f63b15191497068bcbce0ad6ad4f5e4c9ac47d 100644 (file)
@@ -52,12 +52,14 @@ function grep_syscall()
 
        find * -type f \
        |grep '\.c$' \
+       |xargs grep -l "${1}" \
        |sort \
        |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?\)" \
        |sed -E 's/^[^:]+:[0-9]+:/&\n/';
 
        find * -type f \
        |grep '\.[ch]$' \
+       |xargs grep -l "${1}" \
        |sort \
        |xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_${1}\s*\(.*?\)" \
        |sed -E 's/^[^:]+:[0-9]+:/&\n/';
@@ -77,6 +79,7 @@ function grep_syscall_def()
 
        find * -type f \
        |grep '\.c$' \
+       |xargs grep -l "${1}" \
        |sort \
        |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?^}" \
        |sed -E 's/^[^:]+:[0-9]+:/&\n/';
@@ -216,6 +219,7 @@ function grep_glibc_prototype()
 
        find * -type f \
        |grep '\.h$' \
+       |xargs grep -l "${1}" \
        |sort \
        |xargs pcregrep -Mn \
          "(?s)^[\w[][\w\s(,)[:\]]+\s+\**${1}\s*\([\w\s(,)[\]*]+?(...)?\)[\w\s(,)[:\]]*;" \