[PATCH v7 08/10] grep.c: do "if (bool && memchr())" not "if (memchr() && bool)"
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Dec 28, 2021, 01:07 UTC
- Message-ID
- <patch-v7-08.10-7dbeafde26b-20211228T004707Z-avarab@gmail.com>
- In-Reply-To
- <cover-v7-00.10-00000000000-20211228T004707Z-avarab@gmail.com>
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> --- grep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/grep.c b/grep.c index 8dfa0300786..f85be8b6eac 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.34.1.1250.g6a242c1e9ad