This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regmatch(): remove reginput from IFMATCH etc
authorDavid Mitchell <davem@iabyn.com>
Thu, 13 Sep 2012 10:12:40 +0000 (11:12 +0100)
committerDavid Mitchell <davem@iabyn.com>
Fri, 14 Sep 2012 07:49:35 +0000 (08:49 +0100)
It was being used essentially as a temporary var within the branch,
so replace it with a temp var in a new block scope.

On return in IFMATCH_A / IFMATCH_A_fail, there's no need to set reginput
any more, so don't. The SUSPEND case used to set locinput = reginput, but
at that point, the two variables already always had the same value anyway.

This is part of a campaign to eliminate the reginput variable.

regexec.c

index 1556ab6..a1a2a6d 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -5774,9 +5774,12 @@ NULL
 #undef  ST
 #define ST st->u.ifmatch
 
+        {
+            char *newstart;
+
        case SUSPEND:   /* (?>A) */
            ST.wanted = 1;
-           reginput = locinput;
+           newstart = locinput;
            goto do_ifmatch;    
 
        case UNLESSM:   /* -ve lookaround: (?!A), or with flags, (?<!A) */
@@ -5801,10 +5804,10 @@ NULL
                        next = NULL;
                    break;
                }
-               reginput = s;
+               newstart = s;
            }
            else
-               reginput = locinput;
+               newstart = locinput;
 
          do_ifmatch:
            ST.me = scan;
@@ -5812,8 +5815,9 @@ NULL
            logical = 0; /* XXX: reset state of logical once it has been saved into ST */
            
            /* execute body of (?...A) */
-           PUSH_YES_STATE_GOTO(IFMATCH_A, NEXTOPER(NEXTOPER(scan)), reginput);
+           PUSH_YES_STATE_GOTO(IFMATCH_A, NEXTOPER(NEXTOPER(scan)), newstart);
            assert(0); /* NOTREACHED */
+        }
 
        case IFMATCH_A_fail: /* body of (?...A) failed */
            ST.wanted = !ST.wanted;
@@ -5826,10 +5830,9 @@ NULL
            else if (!ST.wanted)
                sayNO;
 
-           if (OP(ST.me) == SUSPEND)
-               locinput = reginput;
-           else {
-               locinput = reginput = st->locinput;
+           if (OP(ST.me) != SUSPEND) {
+                /* restore old position except for (?>...) */
+               locinput = st->locinput;
                nextchr = UCHARAT(locinput);
            }
            scan = ST.me + ARG(ST.me);