This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Convert \d \D to a switch{}
authorKarl Williamson <public@khwilliamson.com>
Mon, 17 Jan 2011 00:41:30 +0000 (17:41 -0700)
committerKarl Williamson <public@khwilliamson.com>
Mon, 17 Jan 2011 16:20:01 +0000 (09:20 -0700)
regcomp.c

index 455c3e9..8260884 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -7471,19 +7471,33 @@ tryagain:
            *flagp |= HASWIDTH|SIMPLE;
            goto finish_meta_pat;
        case 'd':
-            if (LOC) {
-                ret = reg_node(pRExC_state, (U8)(DIGITL));
-            } else {
-                ret = reg_node(pRExC_state, (U8)(DIGIT));
+           switch (get_regex_charset(RExC_flags)) {
+               case REGEX_LOCALE_CHARSET:
+                   op = DIGITL;
+                   break;
+               case REGEX_DEPENDS_CHARSET: /* No difference between these */
+               case REGEX_UNICODE_CHARSET:
+                   op = DIGIT;
+                   break;
+               default:
+                   goto bad_charset;
             }
+           ret = reg_node(pRExC_state, op);
            *flagp |= HASWIDTH|SIMPLE;
            goto finish_meta_pat;
        case 'D':
-            if (LOC) {
-                ret = reg_node(pRExC_state, (U8)(NDIGITL));
-            } else {
-                ret = reg_node(pRExC_state, (U8)(NDIGIT));
+           switch (get_regex_charset(RExC_flags)) {
+               case REGEX_LOCALE_CHARSET:
+                   op = NDIGITL;
+                   break;
+               case REGEX_DEPENDS_CHARSET: /* No difference between these */
+               case REGEX_UNICODE_CHARSET:
+                   op = NDIGIT;
+                   break;
+               default:
+                   goto bad_charset;
             }
+           ret = reg_node(pRExC_state, op);
            *flagp |= HASWIDTH|SIMPLE;
            goto finish_meta_pat;
        case 'R':