From b08fd96f28cc8b2c5b1afb2ddf0f26425f3779af Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 14 Nov 2021 08:12:59 -0800 Subject: [PATCH 07/12] grep: use PCRE2_EXTRA_MATCH_LINE * src/pcresearch.c (Pcompile): If available, use PCRE2_EXTRA_MATCH_LINE instead of doing it by hand. Simplify construction of substitute regular expression. --- src/pcresearch.c | 54 +++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/pcresearch.c b/src/pcresearch.c index fdecbe8..6e1f217 100644 --- a/src/pcresearch.c +++ b/src/pcresearch.c @@ -122,16 +122,8 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact) { PCRE2_SIZE e; int ec; - static char const wprefix[] = "(?cre = pcre2_compile (re, n - (char *)re, flags, &ec, &e, ccontext); + pc->cre = pcre2_compile ((PCRE2_SPTR) pattern, size, flags, + &ec, &e, ccontext); if (!pc->cre) { enum { ERRBUFSIZ = 256 }; /* Taken from pcre2grep.c ERRBUFSIZ. */ @@ -183,6 +189,8 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact) die (EXIT_TROUBLE, 0, "%s", ep); } + free (re_storage); + pc->data = pcre2_match_data_create_from_pattern (pc->cre, NULL); ec = pcre2_jit_compile (pc->cre, PCRE2_JIT_COMPLETE); @@ -194,8 +202,6 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact) pc->jit_stack_size = 32 << 10; } - free (re); - pc->empty_match[false] = jit_exec (pc, "", 0, 0, PCRE2_NOTBOL); pc->empty_match[true] = jit_exec (pc, "", 0, 0, 0); -- 2.32.0