summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2015-09-12 11:39:37 -0600
committerKarl Williamson <khw@cpan.org>2015-09-12 20:50:16 -0600
commit8736d1c336efff364daa33d27d0381c4de4771d0 (patch)
tree284fffa17089eaba562b812f2b9281622d77d10f
parenta229ea8f086a14af7afbad5fa40d1f71e6e48a34 (diff)
downloadperl-8736d1c336efff364daa33d27d0381c4de4771d0.tar.gz
regcomp.c: Simplify some code
Commit 2d3d6e6e7c2d50b1cc47032cf089151823fb20a6 introduced the 'optimizable' variable which if FALSE prevents the [...] node from being optimized, if otherwise possible, into something simpler. It turns out that several of the conditions which prevent such optimization can just clear this flag when they are found, rather than having to test for the conditions again later when the optimization is actually done.
-rw-r--r--embed.fnc2
-rw-r--r--proto.h2
-rw-r--r--regcomp.c31
3 files changed, 17 insertions, 18 deletions
diff --git a/embed.fnc b/embed.fnc
index f1abcd0533..eccc76cfad 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -2131,7 +2131,7 @@ Es |regnode*|regclass |NN RExC_state_t *pRExC_state \
|bool allow_multi_fold \
|const bool silence_non_portable \
|const bool strict \
- |const bool optimizable \
+ |bool optimizable \
|NULLOK SV** ret_invlist
Es |void|add_above_Latin1_folds|NN RExC_state_t *pRExC_state|const U8 cp \
|NN SV** invlist
diff --git a/proto.h b/proto.h
index 4d3465f568..6d32816080 100644
--- a/proto.h
+++ b/proto.h
@@ -4774,7 +4774,7 @@ STATIC regnode* S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth
STATIC regnode* S_regbranch(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, I32 first, U32 depth);
#define PERL_ARGS_ASSERT_REGBRANCH \
assert(pRExC_state); assert(flagp)
-STATIC regnode* S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth, const bool stop_at_1, bool allow_multi_fold, const bool silence_non_portable, const bool strict, const bool optimizable, SV** ret_invlist);
+STATIC regnode* S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth, const bool stop_at_1, bool allow_multi_fold, const bool silence_non_portable, const bool strict, bool optimizable, SV** ret_invlist);
#define PERL_ARGS_ASSERT_REGCLASS \
assert(pRExC_state); assert(flagp)
STATIC unsigned int S_regex_set_precedence(const U8 my_operator)
diff --git a/regcomp.c b/regcomp.c
index e0236cf8e5..fe9b3265c4 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -14254,7 +14254,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
about too large
characters */
const bool strict,
- const bool optimizable, /* ? Allow a non-ANYOF return
+ bool optimizable, /* ? Allow a non-ANYOF return
node */
SV** ret_invlist /* Return an inversion list, not a node */
)
@@ -14703,6 +14703,8 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
(value == 'p' ? '+' : '!'),
UTF8fARG(UTF, n, name));
has_user_defined_property = TRUE;
+ optimizable = FALSE; /* Will have to leave this an
+ ANYOF node */
/* We don't know yet, so have to assume that the
* property could match something in the Latin1 range,
@@ -14937,6 +14939,12 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
}
ANYOF_FLAGS(ret) |= ANYOF_MATCHES_POSIXL;
ANYOF_POSIXL_ZERO(ret);
+
+ /* We can't change this into some other type of node
+ * (unless this is the only element, in which case there
+ * are nodes that mean exactly this) as has runtime
+ * dependencies */
+ optimizable = FALSE;
}
/* Coverity thinks it is possible for this to be negative; both
@@ -15899,7 +15907,11 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
if (warn_super) {
ANYOF_FLAGS(ret)
- |= ANYOF_SHARED_d_MATCHES_ALL_NON_UTF8_NON_ASCII_non_d_WARN_SUPER;
+ |= ANYOF_SHARED_d_MATCHES_ALL_NON_UTF8_NON_ASCII_non_d_WARN_SUPER;
+
+ /* Because an ANYOF node is the only one that warns, this node
+ * can't be optimized into something else */
+ optimizable = FALSE;
}
}
@@ -15987,20 +15999,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
* space). _invlistEQ() could be used if one ever wanted to do something
* like this at this point in the code */
- if ( optimizable
- && cp_list
- && ! invert
- && ! depends_list
- && ! (ANYOF_FLAGS(ret) & (ANYOF_LOCALE_FLAGS))
- && ! HAS_NONLOCALE_RUNTIME_PROPERTY_DEFINITION
-
- /* We don't optimize if we are supposed to make sure all non-Unicode
- * code points raise a warning, as only ANYOF nodes have this check.
- * */
- && ! ((ANYOF_FLAGS(ret) & ANYOF_SHARED_d_MATCHES_ALL_NON_UTF8_NON_ASCII_non_d_WARN_SUPER)
- && OP(ret) != ANYOFD
- && ALWAYS_WARN_SUPER))
- {
+ if (optimizable && cp_list && ! invert && ! depends_list) {
UV start, end;
U8 op = END; /* The optimzation node-type */
const char * cur_parse= RExC_parse;