This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Move [] inversion optimization
authorKarl Williamson <public@khwilliamson.com>
Tue, 7 Dec 2010 23:23:07 +0000 (16:23 -0700)
committerKarl Williamson <public@khwilliamson.com>
Sat, 11 Dec 2010 22:57:58 +0000 (15:57 -0700)
The optimization to do inversion a compile time is moved to earlier.
This doesn't help today, but it may someday when we start keeping better
track of Unicode characters, and is the more logical place for it.

regcomp.c

index 0e3f6ba..50634d2 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -8902,6 +8902,20 @@ parseit:
     if (FOLD && (LOC || ANYOF_FLAGS(ret) & ANYOF_NONBITMAP)) {
         ANYOF_FLAGS(ret) |= ANYOF_FOLD;
     }
+
+    /* Optimize inverted simple patterns (e.g. [^a-z]).  Note that this 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 */
+    if ((ANYOF_FLAGS(ret) & ANYOF_FLAGS_ALL) == ANYOF_INVERT) {
+       for (value = 0; value < ANYOF_BITMAP_SIZE; ++value)
+           ANYOF_BITMAP(ret)[value] ^= 0xFF;
+       stored = 256 - stored;
+
+       /* The inversion means that everything above 255 is matched */
+       ANYOF_FLAGS(ret) = ANYOF_UTF8|ANYOF_UNICODE_ALL;
+    }
+
     if( stored == 1 && (value < 128 || (value < 256 && !UTF))
         && !( ANYOF_FLAGS(ret) & ( ANYOF_FLAGS_ALL ^ ANYOF_FOLD ) )
     ) {
@@ -8926,19 +8940,6 @@ parseit:
         return ret;
     }
 
-    /* Optimize inverted simple patterns (e.g. [^a-z]).  Note that this 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 */
-    if ((ANYOF_FLAGS(ret) & ANYOF_FLAGS_ALL) == ANYOF_INVERT) {
-       for (value = 0; value < ANYOF_BITMAP_SIZE; ++value)
-           ANYOF_BITMAP(ret)[value] ^= 0xFF;
-       stored = 256 - stored;
-
-       /* The inversion means that everything above 255 is matched */
-       ANYOF_FLAGS(ret) = ANYOF_UTF8|ANYOF_UNICODE_ALL;
-    }
-
     {
        AV * const av = newAV();
        SV *rv;