This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regexec(): tidy up ganch-setting code
authorDavid Mitchell <davem@iabyn.com>
Fri, 19 Jul 2013 16:44:34 +0000 (17:44 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sun, 28 Jul 2013 09:33:39 +0000 (10:33 +0100)
Its a bit verbose with tons of debugging statements. Hard to see the wood
for the trees.

regexec.c

index 972f359..d917e4c 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -2260,21 +2260,15 @@ Perl_regexec_flags(pTHX_ REGEXP * const rx, char *stringarg, char *strend,
 
         /* set reginfo->ganch, the position where \G can match */
 
-        if (flags & REXEC_IGNOREPOS){  /* Means: check only at start */
-            reginfo->ganch = stringarg;
-            DEBUG_GPOS_r(PerlIO_printf(Perl_debug_log,
-              "GPOS IGNOREPOS: reginfo->ganch = stringarg\n"));
-        } else if (sv && (mg = mg_find_mglob(sv))
-                  && mg->mg_len >= 0) {
-            reginfo->ganch = strbeg + mg->mg_len;      /* Defined pos() */
-            DEBUG_GPOS_r(PerlIO_printf(Perl_debug_log,
-                "GPOS MAGIC: reginfo->ganch = strbeg + %"IVdf"\n",(IV)mg->mg_len));
-        }
-        else {                         /* pos() not defined */
-            reginfo->ganch = strbeg;
-            DEBUG_GPOS_r(PerlIO_printf(Perl_debug_log,
-                 "GPOS: reginfo->ganch = strbeg\n"));
-        }
+        reginfo->ganch =
+            (flags & REXEC_IGNOREPOS)
+            ? stringarg /* use start pos rather than pos() */
+            : (sv && (mg = mg_find_mglob(sv)) && mg->mg_len >= 0)
+            ? strbeg + mg->mg_len /* Defined pos() */
+            : strbeg; /* pos() not defined; use start of string */
+
+        DEBUG_GPOS_r(PerlIO_printf(Perl_debug_log,
+            "GPOS ganch set to strbeg[%"IVdf"]\n", reginfo->ganch - strbeg));
     }
 
     minlen = prog->minlen;