This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Optimize [^\n] into \N
authorKarl Williamson <public@khwilliamson.com>
Wed, 4 Jul 2012 21:22:59 +0000 (15:22 -0600)
committerKarl Williamson <public@khwilliamson.com>
Wed, 25 Jul 2012 03:13:44 +0000 (21:13 -0600)
This optimization is a big win, as it takes less space, and completely
avoids any swash hash creation, and use.

regcomp.c
t/re/re_tests

index 3ca7a41..7460680 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -11819,7 +11819,10 @@ parseit:
             }
         }
         else if (! LOC) {
-            if (prevvalue == '0' && value == '9') {
+            if (invert && prevvalue == '\n' && value == '\n') {
+                op = REG_ANY; /* Optimize [^\n] */
+            }
+            else if (prevvalue == '0' && value == '9') {
                 op = (invert) ? NDIGITA : DIGITA;
             }
         }
index 5647a4d..46332b4 100644 (file)
@@ -1689,4 +1689,7 @@ ab[c\\\](??{"x"})]{3}d    ab\\](d y       -       -
 /[\H]/ \x{A0}  n       -       -
 /[\H]/ \x{A1}  y       $&      \xA1
 
+[^\n]+ \nb     y       $&      b
+[^\n]+ a\n     y       $&      a
+
 # vim: softtabstop=0 noexpandtab