git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] grep/pcre2: factor out literal variable

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Dec 19, 2021, 19:37 UTC
Message-ID
<211219.86o85cwfje.gmgdl@evledraar.gmail.com>
In-Reply-To
<ba503995-866d-fc80-4e38-b4dfd0e5c5bc@web.de>
On Sat, Dec 18 2021, René Scharfe wrote:
Show 31 quoted lines
> 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.
Previous: René ScharfeNext: Junio C Hamano
Message 3 of 17 in “grep/pcre2: use PCRE2_UTF even with ASCII patterns”
  1. 1/2 grep/pcre2: use PCRE2_UTF even with ASCII patternsRené Scharfe, Dec 18, 2021
  2. 2/2 grep/pcre2: factor out literal variableRené Scharfe, Dec 18, 2021
  3. Ævar Arnfjörð BjarmasonDec 19, 2021
  4. Junio C HamanoDec 20, 2021
  5. Ævar Arnfjörð BjarmasonDec 20, 2021
  6. Junio C HamanoDec 20, 2021
  7. Junio C HamanoDec 20, 2021
  8. [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, Jan 29, 2022
  9. René ScharfeJan 30, 2022
  10. SZEDER GáborJan 30, 2022
  11. René ScharfeJan 30, 2022
  12. Ævar Arnfjörð BjarmasonJan 31, 2022
  13. René ScharfeFeb 5, 2022
  14. SZEDER GáborFeb 6, 2022
  15. Ævar Arnfjörð BjarmasonFeb 12, 2022
  16. René ScharfeFeb 17, 2022
  17. Junio C HamanoFeb 17, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.