This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
re_intuit_start(): check for IMPLICIT in abs anch
authorDavid Mitchell <davem@iabyn.com>
Wed, 19 Mar 2014 16:34:28 +0000 (16:34 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 19 Mar 2014 18:25:55 +0000 (18:25 +0000)
The block of code that deals with absolute anchors looks like:

    if (...) {
        if (.... && !PREGf_IMPLICIT) ...;
        if (FOO) {
            assert(!PREGf_IMPLICIT);
            ....
        }
    }

where the constraints of FOO imply PREGf_IMPLICIT, as shown by the
assertion. Simplify this to:

    if (... && !PREGf_IMPLICIT) {
        if (....) ...;
        if (FOO) {
            ....
        }
    }

regexec.c

index 44fa720..aa9e826 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -755,7 +755,7 @@ Perl_re_intuit_start(pTHX_
         /* Check after \n? */
        ml_anch = (prog->intflags & PREGf_ANCH_MBOL);
 
-       if (!ml_anch) {
+       if (!ml_anch && !(prog->intflags & PREGf_IMPLICIT)) {
             /* we are only allowed to match at BOS or \G */
 
             /* trivially reject if there's a BOS anchor and we're not at BOS.
@@ -775,8 +775,7 @@ Perl_re_intuit_start(pTHX_
              * that we're anchored.
              */
             if (   strpos != strbeg
-                && (prog->intflags & (PREGf_ANCH_BOL|PREGf_ANCH_SBOL))
-                && !(prog->intflags & PREGf_IMPLICIT)) /* not a real BOL */
+                && (prog->intflags & (PREGf_ANCH_BOL|PREGf_ANCH_SBOL)))
             {
                DEBUG_EXECUTE_r(PerlIO_printf(Perl_debug_log,
                                 "  Not at start...\n"));
@@ -798,17 +797,7 @@ Perl_re_intuit_start(pTHX_
             {
                /* Substring at constant offset from beg-of-str... */
                SSize_t slen = SvCUR(check);
-                char *s;
-
-                /* we only get here if there's a fixed substring (min ==
-                 * max). But PREGf_IMPLICIT only gets set if the regex
-                 * begins with /.*.../, and in that case there can't be
-                 * a fixed substring. So assert this truth. If anyone
-                 * changes this assumption (e.g. with lookahead/behind),
-                 * complain and let them fix it */
-                assert(!(prog->intflags & PREGf_IMPLICIT));
-
-               s = HOP3c(strpos, prog->check_offset_min, strend);
+                char *s = HOP3c(strpos, prog->check_offset_min, strend);
            
                 DEBUG_EXECUTE_r(PerlIO_printf(Perl_debug_log,
                     "  Looking for check substr at fixed offset %"IVdf"...\n",