From 7d2d37f505b570402d76d76649cc2464812a5881 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Wed, 19 Mar 2014 16:44:25 +0000 Subject: [PATCH] re_intuit_start(): change definition of ml_anch The ml_anch variable is supposed to indicate that a multi-line match is possible, i.e. that the regex is anchored to a \n. Currently we just do ml_anch = (prog->intflags & PREGf_ANCH_MBOL); However, MBOL is also set on /.*..../; the two cases are distinguished by adding the PREGf_IMPLICIT flag too. So at the moment we have lots of tests along the lines of if (ml_anch && !(prog->intflags & PREGf_IMPLICIT)) Simplify this by adding the IMPLICIT condition when initially calculating ml_anch, so there's no need to keep testing for it later. This also means that ml_anch actually means what it says now. --- regexec.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/regexec.c b/regexec.c index aa9e826..b11159c 100644 --- a/regexec.c +++ b/regexec.c @@ -753,7 +753,8 @@ Perl_re_intuit_start(pTHX_ if (prog->intflags & PREGf_ANCH) { /* Match at \G, beg-of-str or after \n */ /* Check after \n? */ - ml_anch = (prog->intflags & PREGf_ANCH_MBOL); + ml_anch = (prog->intflags & PREGf_ANCH_MBOL) + && !(prog->intflags & PREGf_IMPLICIT); if (!ml_anch && !(prog->intflags & PREGf_IMPLICIT)) { /* we are only allowed to match at BOS or \G */ @@ -905,7 +906,6 @@ Perl_re_intuit_start(pTHX_ */ if (!ml_anch && prog->intflags & PREGf_ANCH - && !(prog->intflags & PREGf_IMPLICIT) && prog->check_offset_max != SSize_t_MAX) { SSize_t len = SvCUR(check) - !!SvTAIL(check); @@ -1145,10 +1145,7 @@ Perl_re_intuit_start(pTHX_ /* handle the extra constraint of /^.../m if present */ - if (ml_anch && rx_origin != strbeg && rx_origin[-1] != '\n' - /* May be due to an implicit anchor of m{.*foo} */ - && !(prog->intflags & PREGf_IMPLICIT)) - { + if (ml_anch && rx_origin != strbeg && rx_origin[-1] != '\n') { char *s; DEBUG_EXECUTE_r(PerlIO_printf(Perl_debug_log, @@ -1268,7 +1265,7 @@ Perl_re_intuit_start(pTHX_ * find_byclass(). */ - if (prog->anchored_substr || prog->anchored_utf8 || (ml_anch && !(prog->intflags & PREGf_IMPLICIT))) + if (prog->anchored_substr || prog->anchored_utf8 || ml_anch) endpos= HOP3c(rx_origin, (prog->minlen ? cl_l : 0), strend); else if (prog->float_substr || prog->float_utf8) { rx_max_float = HOP3c(check_at, -start_shift, strbeg); @@ -1320,7 +1317,7 @@ Perl_re_intuit_start(pTHX_ else { /* float-only */ - if (ml_anch && !(prog->intflags & PREGf_IMPLICIT)) { + if (ml_anch) { /* In the presence of ml_anch, we might be able to * find another \n without breaking the current float * constraint. */ -- 2.7.4