diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-03-17 17:16:24 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-05-27 10:30:01 +0100 |
commit | ded4dd2add376b302c561318612805c584ef9e6a (patch) | |
tree | d57c609654654aca78765f15ef8a852dcfeaf9d1 /regnodes.h | |
parent | 93882df08ca38a02b0381419b29fff019ec87ef7 (diff) | |
download | perl-ded4dd2add376b302c561318612805c584ef9e6a.tar.gz |
Convert REGNODE_{SIMPLE,VARIES} to a bitmask lookup, from a strchr() lookup.
This is O(1) with no branching, instead of O(n) with branching.
Deprecate the old implementation's externally visible variables
PL_simple and PL_varies. Google codesearch suggests that nothing outside the
core regexp code was using these.
Diffstat (limited to 'regnodes.h')
-rw-r--r-- | regnodes.h | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/regnodes.h b/regnodes.h index c9ba1093aa..348410c230 100644 --- a/regnodes.h +++ b/regnodes.h @@ -662,26 +662,34 @@ EXTCONST char * const PL_reg_extflags_name[] = { #endif /* DOINIT */ /* The following have no fixed length. U8 so we can do strchr() on it. */ -#define REGNODE_VARIES(node) strchr((const char *)PL_varies, (node)) +#define REGNODE_VARIES(node) (PL_varies_bitmask[(node) >> 3] & (1 << ((node) & 7))) #ifndef DOINIT -EXTCONST U8 PL_varies[]; +EXTCONST U8 PL_varies[] __attribute__deprecated__; #else -EXTCONST U8 PL_varies[] = { +EXTCONST U8 PL_varies[] __attribute__deprecated__ = { CLUMP, BRANCH, BACK, STAR, PLUS, CURLY, CURLYN, CURLYM, CURLYX, WHILEM, REF, REFF, REFFL, SUSPEND, IFTHEN, BRANCHJ, NREF, NREFF, NREFFL, 0 }; #endif /* DOINIT */ +#ifndef DOINIT +EXTCONST U8 PL_varies_bitmask[]; +#else +EXTCONST U8 PL_varies_bitmask[] = { + 0x00, 0x00, 0x00, 0xC0, 0xC1, 0x9F, 0x33, 0x01, 0x38, 0x00, 0x00, 0x00 +}; +#endif /* DOINIT */ + /* The following always have a length of 1. U8 we can do strchr() on it. */ /* (Note that length 1 means "one character" under UTF8, not "one octet".) */ -#define REGNODE_SIMPLE(node) strchr((const char *)PL_simple, (node)) +#define REGNODE_SIMPLE(node) (PL_simple_bitmask[(node) >> 3] & (1 << ((node) & 7))) #ifndef DOINIT -EXTCONST U8 PL_simple[]; +EXTCONST U8 PL_simple[] __attribute__deprecated__; #else -EXTCONST U8 PL_simple[] = { +EXTCONST U8 PL_simple[] __attribute__deprecated__ = { REG_ANY, SANY, CANY, ANYOF, ALNUM, ALNUML, NALNUM, NALNUML, SPACE, SPACEL, NSPACE, NSPACEL, DIGIT, NDIGIT, VERTWS, NVERTWS, HORIZWS, NHORIZWS, @@ -689,4 +697,12 @@ EXTCONST U8 PL_simple[] = { }; #endif /* DOINIT */ +#ifndef DOINIT +EXTCONST U8 PL_simple_bitmask[]; +#else +EXTCONST U8 PL_simple_bitmask[] = { + 0x00, 0xC0, 0xFF, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00 +}; +#endif /* DOINIT */ + /* ex: set ro: */ |