regcomp.c: Don't restart parse for /d to /u if reparsing anyway
authorKarl Williamson <khw@cpan.org>
Wed, 7 Nov 2018 01:10:36 +0000 (18:10 -0700)
committerKarl Williamson <khw@cpan.org>
Fri, 16 Nov 2018 17:48:19 +0000 (10:48 -0700)
Prior to this commit, if the rules changed from /d to /u, 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.

Doing this can avoid the need for an almost full extra reparse.

regcomp.c

index 6c33b21..1c3664b 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -349,8 +349,12 @@ struct RExC_state_t {
             if (DEPENDS_SEMANTICS) {                                        \
                 set_regex_charset(&RExC_flags, REGEX_UNICODE_CHARSET);      \
                 RExC_uni_semantics = 1;                                     \
+                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