summaryrefslogtreecommitdiff
path: root/regcomp.h
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2010-11-11 20:07:09 -0700
committerFather Chrysostomos <sprout@cpan.org>2010-11-22 13:32:50 -0800
commitcefafd73018b048fa66d2b22250431112141955a (patch)
tree3fceda48445d91fea7e34f4e6a5a74a5a2588a30 /regcomp.h
parentc355c09a82f4c7345a6bafa5322643acdb584e80 (diff)
downloadperl-cefafd73018b048fa66d2b22250431112141955a.tar.gz
regex free up bit in ANYOF node
This patch causes all locale ANYOF nodes to have a class bitmap (4 bytes) even if they don't have a class (such as \w, \d, [:posix:]). This frees up a bit in the flags field that was used to signal if the node had the bitmap. I intend to use it instead to signal that loading a swash, which is slow, can be bypassed. Thus this is a time/space tradeoff, applicable to not just locale nodes: adding a word to the locale nodes saves time for all nodes. I added the ANYOF_CLASS_TEST_ANY_SET() macro to determine quickly if there are actually any classes in the node. Minimal code was changed, so this can be easily reversed if another bit frees up. Another possibility is to share with the ANYOF_EOS bit instead, as this is used just in the optimizer's start class, and only in regcomp.c. But this requires more careful coding. Another possibility is to add a byte (hence likely at least 4 because of alignment issues) to store extra flags. And still another possibility is to add just the byte for the start class, which would not need to affect other ANYOF nodes, since the EOS bit is not used outside regcomp.c. But various routines in regcomp assume that the start class and other ANYOF nodes are interchangeable, so this option would require more code changes.
Diffstat (limited to 'regcomp.h')
-rw-r--r--regcomp.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/regcomp.h b/regcomp.h
index 3e541100d7..7b73b02b42 100644
--- a/regcomp.h
+++ b/regcomp.h
@@ -319,7 +319,8 @@ struct regnode_charclass_class {
#define ANYOF_INVERT 0x04
/* CLASS is never set unless LOCALE is too: has runtime \d, \w, [:posix:], ... */
-#define ANYOF_CLASS 0x08
+/* For now, set it always when LOCALE is set, to save a bit for other uses. */
+#define ANYOF_CLASS ANYOF_LOCALE
#define ANYOF_LARGE ANYOF_CLASS /* Same; name retained for back compat */
/* EOS used for regstclass only */
@@ -396,6 +397,12 @@ struct regnode_charclass_class {
#define ANYOF_CLASS_CLEAR(p, c) (ANYOF_CLASS_BYTE(p, c) &= ~ANYOF_BIT(c))
#define ANYOF_CLASS_TEST(p, c) (ANYOF_CLASS_BYTE(p, c) & ANYOF_BIT(c))
+/* Quicker way to see if there are actually any tests. This is because
+ * currently the set of tests can be empty even when the class bitmap is
+ * allocated */
+#define ANYOF_CLASS_TEST_ANY_SET(p) /* assumes sizeof(p) = 4 */ \
+ memNE (((struct regnode_charclass_class*)(p))->classflags, "0000", ANYOF_CLASS_SIZE)
+
#define ANYOF_CLASS_ZERO(ret) Zero(((struct regnode_charclass_class*)(ret))->classflags, ANYOF_CLASSBITMAP_SIZE, char)
#define ANYOF_BITMAP_ZERO(ret) Zero(((struct regnode_charclass*)(ret))->bitmap, ANYOF_BITMAP_SIZE, char)