This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Optimize /[a-z]/ and /[A-Z]/
authorKarl Williamson <khw@cpan.org>
Sun, 27 Apr 2014 16:53:00 +0000 (10:53 -0600)
committerKarl Williamson <khw@cpan.org>
Fri, 30 May 2014 16:24:27 +0000 (10:24 -0600)
These bracketed character classes can easily be optimized into smaller
probably faster regops that match identically.

regcomp.c

index 4cd50ee..236cb24 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -14201,6 +14201,26 @@ parseit:
                     op = POSIXA;
                 }
             }
+            else if (prevvalue == 'A') {
+                if (value == 'Z'
+#ifdef EBCDIC
+                    && literal_endpoint == 2
+#endif
+                ) {
+                    arg = (FOLD) ? _CC_ALPHA : _CC_UPPER;
+                    op = POSIXA;
+                }
+            }
+            else if (prevvalue == 'a') {
+                if (value == 'z'
+#ifdef EBCDIC
+                    && literal_endpoint == 2
+#endif
+                ) {
+                    arg = (FOLD) ? _CC_ALPHA : _CC_LOWER;
+                    op = POSIXA;
+                }
+            }
         }
 
         /* Here, we have changed <op> away from its initial value iff we found