This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regmatch(): remove reginput from CURLYM
authorDavid Mitchell <davem@iabyn.com>
Thu, 13 Sep 2012 10:38:26 +0000 (11:38 +0100)
committerDavid Mitchell <davem@iabyn.com>
Fri, 14 Sep 2012 07:49:35 +0000 (08:49 +0100)
reginput, locinput and st->locinput were being used in a little
ballet to determine the length of the first match.
This is now simply locinput - st->locinput, or its unicode equivalent;
so the code can be simplified.

Elsewhere in the block: where reginput was being used, locinput and/or
nextchr already contain the same info, so use them instead.

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

regexec.c

index a1a2a6d..9c423ed 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -5235,21 +5235,18 @@ NULL
            assert(0); /* NOTREACHED */
 
        case CURLYM_A: /* we've just matched an A */
-           locinput = st->locinput;
-           nextchr = UCHARAT(locinput);
-
            ST.count++;
            /* after first match, determine A's length: u.curlym.alen */
            if (ST.count == 1) {
                if (PL_reg_match_utf8) {
-                   char *s = locinput;
-                   while (s < reginput) {
+                   char *s = st->locinput;
+                   while (s < locinput) {
                        ST.alen++;
                        s += UTF8SKIP(s);
                    }
                }
                else {
-                   ST.alen = reginput - locinput;
+                   ST.alen = locinput - st->locinput;
                }
                if (ST.alen == 0)
                    ST.count = ST.minmod ? ARG1(ST.me) : ARG2(ST.me);
@@ -5261,8 +5258,6 @@ NULL
                          (IV) ST.count, (IV)ST.alen)
            );
 
-           locinput = reginput;
-                       
            if (cur_eval && cur_eval->u.eval.close_paren && 
                cur_eval->u.eval.close_paren == (U32)ST.me->flags) 
                goto fake_end;
@@ -5283,7 +5278,6 @@ NULL
                sayNO;
 
          curlym_do_B: /* execute the B in /A{m,n}B/  */
-           reginput = locinput;
            if (ST.c1 == CHRTEST_UNINIT) {
                /* calculate c1 and c2 for possible match of 1st char
                 * following curly */
@@ -5325,8 +5319,8 @@ NULL
                    "", (IV)ST.count)
                );
            if (ST.c1 != CHRTEST_VOID
-                   && UCHARAT(reginput) != ST.c1
-                   && UCHARAT(reginput) != ST.c2)
+                   && nextchr != ST.c1
+                   && nextchr != ST.c2)
            {
                /* simulate B failing */
                DEBUG_OPTIMISE_r(
@@ -5344,8 +5338,8 @@ NULL
                I32 paren = ST.me->flags;
                if (ST.count) {
                    rex->offs[paren].start
-                       = HOPc(reginput, -ST.alen) - PL_bostr;
-                   rex->offs[paren].end = reginput - PL_bostr;
+                       = HOPc(locinput, -ST.alen) - PL_bostr;
+                   rex->offs[paren].end = locinput - PL_bostr;
                    if ((U32)paren > rex->lastparen)
                        rex->lastparen = paren;
                    rex->lastcloseparen = paren;
@@ -5379,6 +5373,7 @@ NULL
                sayNO;
            ST.count--;
            locinput = HOPc(locinput, -ST.alen);
+            nextchr = UCHARAT(locinput);
            goto curlym_do_B; /* try to match B */
 
 #undef ST