diff options
author | Karl Williamson <public@khwilliamson.com> | 2012-06-27 16:24:43 -0600 |
---|---|---|
committer | Karl Williamson <public@khwilliamson.com> | 2012-06-29 22:22:42 -0600 |
commit | 3a64b5154fffec75126d34d25954f0aef30d9f8a (patch) | |
tree | 6dc830e8e90dbd642c45ccf285bbf1c695bbf758 /regcomp.c | |
parent | 3172e3fd885a9c54105d3b6156f18dc761fe29e5 (diff) | |
download | perl-3a64b5154fffec75126d34d25954f0aef30d9f8a.tar.gz |
regcomp.c: Optimize /[0-9]/ into /\d/a
The commonly used [0-9] can be optimized into a smaller, faster node
that means the same thing.
Diffstat (limited to 'regcomp.c')
-rw-r--r-- | regcomp.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -11710,8 +11710,13 @@ parseit: } /* [\w] can be optimized into \w, but not if there is anything else in the - * brackets (except for an initial '^' which indictes omplementing) */ - if (element_count == 1 && (has_special_charset_op || has_special_non_charset_op)) { + * brackets (except for an initial '^' which indictes omplementing). We + * also can optimize the common special case /[0-9]/ into /\d/a */ + if (element_count == 1 && + (has_special_charset_op + || has_special_non_charset_op + || (prevvalue == '0' && value == '9'))) + { U8 op; bool invert = ANYOF_FLAGS(ret) & ANYOF_INVERT; const char * cur_parse = RExC_parse; @@ -11783,6 +11788,9 @@ parseit: op++; } } + else { /* The remaining possibility is [0-9] */ + op = (invert) ? NDIGITA : DIGITA; + } /* Throw away this ANYOF regnode, and emit the calculated one, which * should correspond to the beginning, not current, state of the parse |