From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: "Git List" <git@vger.kernel.org>,
"Hamza Mahfooz" <someguy@effective-light.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Carlo Marcelo Arenas Belón" <carenas@gmail.com>,
"Andreas Schwab" <schwab@linux-m68k.org>
Subject: Re: [PATCH 2/2] grep/pcre2: factor out literal variable
Date: Sun, 19 Dec 2021 20:37:37 +0100 [thread overview]
Message-ID: <211219.86o85cwfje.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <ba503995-866d-fc80-4e38-b4dfd0e5c5bc@web.de>
On Sat, Dec 18 2021, René Scharfe wrote:
> Patterns that contain no wildcards and don't have to be case-folded are
> literal. Give this condition a name to increase the readability of the
> boolean expression for enabling the option PCRE2_UTF.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> grep.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/grep.c b/grep.c
> index 5badb6d851..2b6ac3205d 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -362,6 +362,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
> int jitret;
> int patinforet;
> size_t jitsizearg;
> + int literal = !opt->ignore_case && (p->fixed || p->is_fixed);
>
> /*
> * Call pcre2_general_context_create() before calling any
> @@ -382,8 +383,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
> }
> options |= PCRE2_CASELESS;
> }
> - if (!opt->ignore_locale && is_utf8_locale() &&
> - !(!opt->ignore_case && (p->fixed || p->is_fixed)))
> + if (!opt->ignore_locale && is_utf8_locale() && !literal)
> options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF);
>
> #ifdef GIT_PCRE2_VERSION_10_36_OR_HIGHER
I think for this and 1/2 it would be really nice to pick up a version of
Hamza's CI changes:
https://lore.kernel.org/git/20211118084143.279174-2-someguy@effective-light.com/
Aside: Not needed for this change, but I wonder if we could benefit minutely
from:
#ifdef PCRE2_LITERAL
options |= PCRE2_LITERAL;
#endif
It'll save PCRE2 the small effort of finding that we've got no metacharacters.
next prev parent reply other threads:[~2021-12-19 19:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-18 19:50 [PATCH 1/2] grep/pcre2: use PCRE2_UTF even with ASCII patterns René Scharfe
2021-12-18 19:53 ` [PATCH 2/2] grep/pcre2: factor out literal variable René Scharfe
2021-12-19 19:37 ` Ævar Arnfjörð Bjarmason [this message]
2021-12-20 20:52 ` Junio C Hamano
2021-12-20 22:03 ` Ævar Arnfjörð Bjarmason
2021-12-20 20:53 ` Junio C Hamano
2021-12-20 20:47 ` Junio C Hamano
2022-01-29 17:25 ` [v2.35.0 regression] some PCRE hangs under UTF-8 locale (was: [PATCH 1/2] grep/pcre2: use PCRE2_UTF even with ASCII patterns) SZEDER Gábor
2022-01-30 7:55 ` René Scharfe
2022-01-30 9:04 ` SZEDER Gábor
2022-01-30 13:32 ` René Scharfe
2022-01-31 21:01 ` Ævar Arnfjörð Bjarmason
2022-02-05 17:00 ` René Scharfe
2022-02-06 10:08 ` SZEDER Gábor
2022-02-12 20:46 ` Ævar Arnfjörð Bjarmason
2022-02-17 21:14 ` René Scharfe
2022-02-17 22:56 ` [v2.35.0 regression] some PCRE hangs under UTF-8 locale Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=211219.86o85cwfje.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=carenas@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=schwab@linux-m68k.org \
--cc=someguy@effective-light.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).