This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Clean up ANYOF_CLASS handling.
authorKarl Williamson <public@khwilliamson.com>
Thu, 27 Dec 2012 19:34:41 +0000 (12:34 -0700)
committerKarl Williamson <public@khwilliamson.com>
Fri, 28 Dec 2012 17:38:55 +0000 (10:38 -0700)
The ANYOF_CLASS flag is used in ANYOF nodes (for [bracketed] and the
synthetic start class) only when matching something like \w, [:punct:]
etc., under /l (locale).  It should not be set unless /l is specified.
However, it was always getting set for the synthetic start class.  This
commit fixes that.  The previous code was masking errors in which it was
being tested for unnecessarily, and for much of the 5.17 series, the
synthetic start class was always set to test for locale, which was a
waste of cpu when no locale was specified.

regcomp.c
regcomp.h
t/re/re_tests

index eee952f..bf8d7e0 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -756,7 +756,7 @@ S_cl_anything(const RExC_state_t *pRExC_state, struct regnode_charclass_class *c
     PERL_ARGS_ASSERT_CL_ANYTHING;
 
     ANYOF_BITMAP_SETALL(cl);
-    cl->flags = ANYOF_CLASS|ANYOF_EOS|ANYOF_UNICODE_ALL
+    cl->flags = ANYOF_EOS|ANYOF_UNICODE_ALL
                |ANYOF_NON_UTF8_LATIN1_ALL;
 
     /* If any portion of the regex is to operate under locale rules,
@@ -768,7 +768,7 @@ S_cl_anything(const RExC_state_t *pRExC_state, struct regnode_charclass_class *c
      * necessary. */
     if (RExC_contains_locale) {
        ANYOF_CLASS_SETALL(cl);     /* /l uses class */
-       cl->flags |= ANYOF_LOCALE|ANYOF_LOC_FOLD;
+       cl->flags |= ANYOF_LOCALE|ANYOF_CLASS|ANYOF_LOC_FOLD;
     }
     else {
        ANYOF_CLASS_ZERO(cl);       /* Only /l uses class now */
@@ -3549,7 +3549,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
                 * utf8 string, so accept a possible false positive for
                 * latin1-range folds */
                if (uc >= 0x100 ||
-                   (!(data->start_class->flags & (ANYOF_CLASS | ANYOF_LOCALE))
+                   (!(data->start_class->flags & ANYOF_LOCALE)
                    && !ANYOF_BITMAP_TEST(data->start_class, uc)
                    && (!(data->start_class->flags & ANYOF_LOC_FOLD)
                        || !ANYOF_BITMAP_TEST(data->start_class, PL_fold_latin1[uc])))
@@ -3626,7 +3626,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
                /* Check whether it is compatible with what we know already! */
                int compat = 1;
                if (uc >= 0x100 ||
-                (!(data->start_class->flags & (ANYOF_CLASS | ANYOF_LOCALE))
+                (!(data->start_class->flags & ANYOF_LOCALE)
                  && !ANYOF_BITMAP_TEST(data->start_class, uc)
                  && !ANYOF_BITMAP_TEST(data->start_class, PL_fold_latin1[uc])))
                {
index 8eb849c..be3970d 100644 (file)
--- a/regcomp.h
+++ b/regcomp.h
@@ -488,7 +488,7 @@ struct regnode_charclass_class {
 #define ANYOF_CLASS_SKIP       ((ANYOF_CLASS_SIZE - 1)/sizeof(regnode))
 
 #define ANYOF_CLASS_TEST_ANY_SET(p)                               \
-        ((ANYOF_FLAGS(p) & (ANYOF_CLASS|ANYOF_IS_SYNTHETIC))         \
+        ((ANYOF_FLAGS(p) & ANYOF_CLASS)                           \
         && (((struct regnode_charclass_class*)(p))->classflags))
 /*#define ANYOF_CLASS_ADD_SKIP (ANYOF_CLASS_SKIP - ANYOF_SKIP)
  * */
index 97b1e9f..9da8491 100644 (file)
@@ -1719,4 +1719,6 @@ ab[c\\\](??{"x"})]{3}d    ab\\](d y       -       -
 # [ perl #114272]
 \Vn    \xFFn/  y       $&      \xFFn
 
+/(?l:a?\w)/    b       y       $&      b
+
 # vim: softtabstop=0 noexpandtab