Thread (117 messages) flat view 117 messages, 3 authors, 2022-03-04
STALE1655d

Revision v10 of 5 in this series.

Revisions (5)
  1. v7 [diff vs current]
  2. v8 [diff vs current]
  3. v9 [diff vs current]
  4. v10 current
  5. v11 [diff vs current]

[PATCH v10 8/9] grep.c: do "if (bool && memchr())" not "if (memchr() && bool)"

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2022-02-04 21:21:15
Subsystem: the rest · Maintainer: Linus Torvalds

Change code in compile_regexp() to check the cheaper boolean
"!opt->pcre2" condition before the "memchr()" search.

This doesn't noticeably optimize anything, but makes the code more
obvious and conventional. The line wrapping being added here also
makes a subsequent commit smaller.

Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
 grep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/grep.c b/grep.c
index 35e12e43c09..60228a95a4f 100644
--- a/grep.c
+++ b/grep.c
@@ -492,7 +492,8 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
 	p->ignore_case = opt->ignore_case;
 	p->fixed = opt->fixed;
 
-	if (memchr(p->pattern, 0, p->patternlen) && !opt->pcre2)
+	if (!opt->pcre2 &&
+	    memchr(p->pattern, 0, p->patternlen))
 		die(_("given pattern contains NULL byte (via -f <file>). This is only supported with -P under PCRE v2"));
 
 	p->is_fixed = is_fixed(p->pattern, p->patternlen);
-- 
2.35.1.940.ge7a5b4b05f2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help