summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-02-16 00:00:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-02-16 02:00:50 (GMT)
commitae807d778f502c81ec55897ac6d1f42ef3a4e23b (patch)
tree63d0cea93f9e17d7b54a277a6e1f6788a76cd2d4 /grep.c
parent321ee43628c53d6050fb7fbc552332bab681f1a4 (diff)
downloadgit-ae807d778f502c81ec55897ac6d1f42ef3a4e23b.zip
git-ae807d778f502c81ec55897ac6d1f42ef3a4e23b.tar.gz
git-ae807d778f502c81ec55897ac6d1f42ef3a4e23b.tar.bz2
grep.c: do "if (bool && memchr())" not "if (memchr() && bool)"
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>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/grep.c b/grep.c
index 35e12e4..60228a9 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);