regcomp.c: Don't restart parse now if doing so later
authorKarl Williamson <khw@cpan.org>
Wed, 7 Nov 2018 01:02:07 +0000 (18:02 -0700)
committerKarl Williamson <khw@cpan.org>
Fri, 16 Nov 2018 17:48:18 +0000 (10:48 -0700)
Prior to this commit, if it became apparent that long branches were
going to be needed, the parse was immediately restarted.  This commit
changes that so that it doesn't do this if it is known that the parse
will be redone anyway, but a full parse needs to done first in order to
count the parentheses.

This can avoid an almost complete reparse in some situations.

regcomp.c

index 758bc33..6c33b21 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -358,8 +358,12 @@ struct RExC_state_t {
 #define REQUIRE_BRANCHJ(flagp, restart_retval)                              \
     STMT_START {                                                            \
                 RExC_use_BRANCHJ = 1;                                       \
-                *flagp |= RESTART_PARSE;                                    \
-                return restart_retval;                                      \
+                if (LIKELY(RExC_total_parens >= 0)) {                       \
+                    /* No need to restart the parse immediately if we're    \
+                     * going to reparse anyway to count parens */           \
+                    *flagp |= RESTART_PARSE;                                \
+                    return restart_retval;                                  \
+                }                                                           \
     } STMT_END
 
 #define REQUIRE_PARENS_PASS                                                 \