summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2012-07-09 22:00:16 -0600
committerKarl Williamson <public@khwilliamson.com>2012-07-24 21:13:48 -0600
commitce712dffad41e08420bdc13aa14486bb92469cc2 (patch)
treeacd5cac1bd9011f68a3ac8a5d0b58340d08a5e4f
parent76a181d97532f0ae916ffcf05852248c93e97620 (diff)
downloadperl-ce712dffad41e08420bdc13aa14486bb92469cc2.tar.gz
regcomp.c: Relax some restrictions on optimizations for locale
Prior to this commit, we didn't do any inversions for bracketed character classes running under locale. However, this is more strict than necessary. If there is no folding, and everything else is known at compile time, then what is matched when the result is complemented is well-defined, and can be done now. (Also clarifies one of the affected comments)
-rw-r--r--regcomp.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/regcomp.c b/regcomp.c
index c237c64aad..5a87e9cc61 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -12397,15 +12397,14 @@ parseit:
* Now we can see about various optimizations. Fold calculation (which we
* did above) needs to take place before inversion. Otherwise /[^k]/i
* would invert to include K, which under /i would match k, which it
- * shouldn't. */
+ * shouldn't. Therefore we can't invert folded locale now, as it won't be
+ * folded until runtime */
- /* Optimize inverted simple patterns (e.g. [^a-z]). Note that we haven't
- * set the FOLD flag yet, so this does optimize those. It doesn't
- * optimize locale. Doing so perhaps could be done as long as there is
- * nothing like \w in it; some thought also would have to be given to the
- * interaction with above 0x100 chars */
+ /* Optimize inverted simple patterns (e.g. [^a-z]) when everything is known
+ * at compile time. Besides not inverting folded locale now, we can't invert
+ * if there are things such as \w, which aren't known until runtime */
if (invert
- && ! LOC
+ && ! (LOC && (FOLD || (ANYOF_FLAGS(ret) & ANYOF_CLASS)))
&& ! depends_list
&& ! unicode_alternate
&& ! HAS_NONLOCALE_RUNTIME_PROPERTY_DEFINITION)