This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Move test earlier in regpiece()
authorKarl Williamson <khw@cpan.org>
Tue, 21 Apr 2020 12:26:58 +0000 (06:26 -0600)
committerKarl Williamson <khw@cpan.org>
Mon, 12 Oct 2020 15:45:46 +0000 (09:45 -0600)
Prior to this commit, the code checked if this was a particular
quantifier; if so handled that, then checked if it were some other
quantifier, returning if not.

This commit changes to check first if it is any quantifier, using the
macro that checks for all of them, returning if not.

Thus after the new code we know it is a quantifier and this allows later
commits to simplify

regcomp.c

index 88e55ae..a3186dd 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -12624,9 +12624,17 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
         FAIL2("panic: regatom returned failure, flags=%#" UVxf, (UV) flags);
     }
 
+    if (! ISMULT2(RExC_parse)) {
+       *flagp = flags;
+       return(ret);
+    }
+
+    /* Here we know the input is a legal quantifier, including {m,n} */
+
     op = *RExC_parse;
 
-    if (op == '{' && regcurly(RExC_parse)) {
+    if (op == '{') {
+        const char* endptr;
        maxpos = NULL;
 #ifdef RE_TRACK_PATTERN_OFFSETS
         parse_start = RExC_parse; /* MJD */
@@ -12641,8 +12649,9 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
            }
            next++;
        }
-       if (*next == '}') {             /* got one */
-            const char* endptr;
+
+       assert(*next == '}');
+
            if (!maxpos)
                maxpos = next;
            RExC_parse++;
@@ -12764,12 +12773,6 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                 RExC_seen |= REG_UNBOUNDED_QUANTIFIER_SEEN;
 
            goto nest_check;
-       }
-    }
-
-    if (!ISMULT1(op)) {
-       *flagp = flags;
-       return(ret);
     }
 
 #if 0                          /* Now runtime fix should be reliable. */