From b25a103638bc5111446c1e65a21db00a6e13acc1 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Thu, 27 Dec 2012 12:34:41 -0700 Subject: [PATCH] regcomp.c: Clean up ANYOF_CLASS handling. 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 | 8 ++++---- regcomp.h | 2 +- t/re/re_tests | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/regcomp.c b/regcomp.c index eee952f..bf8d7e0 100644 --- 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]))) { diff --git a/regcomp.h b/regcomp.h index 8eb849c..be3970d 100644 --- 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) * */ diff --git a/t/re/re_tests b/t/re/re_tests index 97b1e9f..9da8491 100644 --- a/t/re/re_tests +++ b/t/re/re_tests @@ -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 -- 2.7.4