summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-11-06 18:02:07 -0700
committerKarl Williamson <khw@cpan.org>2018-11-16 10:48:18 -0700
commit523a2924740c68b1653d1c68aea5c8d7fb9161e4 (patch)
tree87ade84a78e2664e942b899dafb4bfed3faed1e6
parent2ac479f0aebdb9a80e57fb49182be8ddfed7a35f (diff)
downloadperl-523a2924740c68b1653d1c68aea5c8d7fb9161e4.tar.gz
regcomp.c: Don't restart parse now if doing so later
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.
-rw-r--r--regcomp.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/regcomp.c b/regcomp.c
index 758bc33dd4..6c33b219c5 100644
--- 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 \