re_intuit_start(): simplify fixed offset_max code
authorDavid Mitchell <davem@iabyn.com>
Mon, 20 Jan 2014 16:51:31 +0000 (16:51 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 7 Feb 2014 22:39:37 +0000 (22:39 +0000)
Since we now assert that all offsets are non-negative, this code can
be simplified a bit. Also, by using HOP3lim() rather than HOP3(), we can
remove a trailing conditional.

regexec.c

index 0278aba..86e7615 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -832,22 +832,17 @@ Perl_re_intuit_start(pTHX_
             end_point= HOP3(strend, -end_shift, strbeg);
        }
 
+        /* if the regex is absolutely anchored to the start of the string,
+         * then check_offset_max represents an upper bound on the string
+         * where the substr could start */
         if (!ml_anch
             && prog->intflags & PREGf_ANCH
-            && prog->check_offset_max != SSize_t_MAX)
+            && prog->check_offset_max != SSize_t_MAX
+            && start_shift < prog->check_offset_max)
         {
-            U8 *p = (U8*)s;
-
-            if (start_shift > 0)
-                p = start_point; /* don't HOP over chars already HOPed */
-            if (p < end_point)
-                p = HOP3(p,
-                        (prog->check_offset_max
-                         - (start_shift > 0 ? start_shift : 0)
-                         + CHR_SVLEN(check) - (SvTAIL(check) != 0)),
-                        end_point);
-            if (p < end_point)
-                end_point = p;
+            SSize_t off = prog->check_offset_max - start_shift
+                        + CHR_SVLEN(check) - !!SvTAIL(check);
+            end_point = HOP3lim(start_point, off, end_point);
         }
 
        DEBUG_OPTIMISE_MORE_r({