This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regmatch(): remove reginput from TRIE_next_fail:
authorDavid Mitchell <davem@iabyn.com>
Thu, 13 Sep 2012 09:28:11 +0000 (10:28 +0100)
committerDavid Mitchell <davem@iabyn.com>
Fri, 14 Sep 2012 07:49:34 +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.

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

regexec.c

index e009173..1556ab6 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -3609,6 +3609,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
            assert(0); /* NOTREACHED */
 
        case TRIE_next_fail: /* we failed - try next alternative */
+        {
+            U8 *uc;
             if ( ST.jump) {
                 REGCP_UNWIND(ST.cp);
                 UNWIND_PAREN(ST.lastparen, ST.lastcloseparen);
@@ -3653,7 +3655,6 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
            /* find start char of end of current word */
            {
                U32 chars; /* how many chars to skip */
-               U8 *uc = ST.firstpos;
                reg_trie_data * const trie
                    = (reg_trie_data*)rexi->data->data[ARG(ST.me)];
 
@@ -3661,6 +3662,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                            >=  ST.firstchars);
                chars = (trie->wordinfo[ST.nextword].len - trie->prefixlen)
                            - ST.firstchars;
+               uc = ST.firstpos;
 
                if (ST.longfold) {
                    /* the hard option - fold each char in turn and find
@@ -3700,7 +3702,6 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                    else
                        uc += chars;
                }
-               reginput = (char *)uc;
            }
 
            scan = ST.me + ((ST.jump && ST.jump[ST.nextword])
@@ -3718,7 +3719,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
            });
 
            if (ST.accepted > 1 || has_cutgroup) {
-               PUSH_STATE_GOTO(TRIE_next, scan, reginput);
+               PUSH_STATE_GOTO(TRIE_next, scan, (char*)uc);
                assert(0); /* NOTREACHED */
            }
            /* only one choice left - just continue */
@@ -3741,10 +3742,11 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                    PL_colors[5] );
            });
 
-           locinput = reginput;
+           locinput = (char*)uc;
            nextchr = UCHARAT(locinput);
            continue; /* execute rest of RE */
            assert(0); /* NOTREACHED */
+        }
 #undef  ST
 
        case EXACT: {