From ccd5ac9014cf661fbd2fb755a903ea8c5b84111d Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Fri, 3 Oct 2014 09:47:59 +0000 Subject: [PATCH] Save compile-time work when PCRE2_NO_START_OPTIMIZE is set. --- src/pcre2_compile.c | 19 ++++++++++++------- testdata/testinput2 | 4 ++++ testdata/testoutput2 | 11 +++++++++++ testdata/testoutput6 | 3 +-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index 664a4fc..45518b4 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -7883,9 +7883,11 @@ if ((re->overall_options & PCRE2_ANCHORED) == 0 && /* If the pattern is still not anchored and we do not have a first code unit, see if there is one that is asserted (these are not saved during the compile -because they can cause conflicts with actual literals that follow). */ +because they can cause conflicts with actual literals that follow). This code +need not be obeyed if PCRE2_NO_START_OPTIMIZE is set, as the data it would +create will not be used. */ -if ((re->overall_options & PCRE2_ANCHORED) == 0) +if ((re->overall_options & (PCRE2_ANCHORED|PCRE2_NO_START_OPTIMIZE)) == 0) { if (firstcuflags < 0) firstcu = find_firstassertedcu(codestart, &firstcuflags, FALSE); @@ -7928,10 +7930,11 @@ if ((re->overall_options & PCRE2_ANCHORED) == 0) } /* Handle the "required code unit", if one is set. In the case of an anchored -pattern, do this only if it follows a variable length item in the pattern. */ +pattern, do this only if it follows a variable length item in the pattern. +Again, skip this if PCRE2_NO_START_OPTIMIZE is set. */ if (reqcuflags >= 0 && - ((re->overall_options & PCRE2_ANCHORED) == 0 || + ((re->overall_options & (PCRE2_ANCHORED|PCRE2_NO_START_OPTIMIZE)) == 0 || (reqcuflags & REQ_VARY) != 0)) { re->last_codeunit = reqcu; @@ -7966,10 +7969,12 @@ do } while (*codestart == OP_ALT); -/* Finally, study the compiled pattern to set up information such as a bitmap -of starting code units and a minimum matching length. */ +/* Finally, unless PCRE2_NO_START_OPTIMIZE is set, study the compiled pattern +to set up information such as a bitmap of starting code units and a minimum +matching length. */ -if (PRIV(study)(re) != 0) +if ((re->overall_options & PCRE2_NO_START_OPTIMIZE) == 0 && + PRIV(study)(re) != 0) { errorcode = ERR31; goto HAD_ERROR; diff --git a/testdata/testinput2 b/testdata/testinput2 index 632abe2..24f82c6 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -4091,4 +4091,8 @@ a random value. /Ix /(?(VERSION>=10.0.0)yes|no)/ +/abcd/I + +/abcd/I,no_start_optimize + # End of testinput2 diff --git a/testdata/testoutput2 b/testdata/testoutput2 index aed60b7..d9b457c 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -13769,4 +13769,15 @@ Failed: error 179 at offset 11: syntax error in (?(VERSION condition /(?(VERSION>=10.0.0)yes|no)/ Failed: error 179 at offset 16: syntax error in (?(VERSION condition +/abcd/I +Capturing subpattern count = 0 +First code unit = 'a' +Last code unit = 'd' +Subject length lower bound = 4 + +/abcd/I,no_start_optimize +Capturing subpattern count = 0 +Options: no_start_optimize +Subject length lower bound = 0 + # End of testinput2 diff --git a/testdata/testoutput6 b/testdata/testoutput6 index 9dd1fdc..e37369b 100644 --- a/testdata/testoutput6 +++ b/testdata/testoutput6 @@ -7127,8 +7127,7 @@ No match /(abc|def|xyz)/I,no_start_optimize Capturing subpattern count = 1 Options: no_start_optimize -Starting code units: a d x -Subject length lower bound = 3 +Subject length lower bound = 0 terhjk;abcdaadsfe 0: abc the quick xyz brown fox