]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep.c: do "if (bool && memchr())" not "if (memchr() && bool)"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 16 Feb 2022 00:00:38 +0000 (01:00 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Feb 2022 02:00:50 +0000 (18:00 -0800)
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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c

diff --git a/grep.c b/grep.c
index 35e12e43c09fe794b250d1e2264eee684cbd36f1..60228a95a4f745c71319a5c1751a496e0593a28d 100644 (file)
--- 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);