From: Nicholas Clark Date: Sat, 24 Nov 2001 16:30:42 +0000 (+0000) Subject: memset() is cheaper than a loop of 256 bit-a-a-times X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f8bef55053427841654eec6e37b8f0f4224b2976;p=p5sagit%2Fp5-mst-13.2.git memset() is cheaper than a loop of 256 bit-a-a-times Message-ID: <20011124163042.R37621@plum.flirble.org> p4raw-id: //depot/perl@13236 --- diff --git a/regcomp.c b/regcomp.c index 3eb4e39..c73e815 100644 --- a/regcomp.c +++ b/regcomp.c @@ -522,11 +522,8 @@ S_scan_commit(pTHX_ RExC_state_t *pRExC_state, scan_data_t *data) STATIC void S_cl_anything(pTHX_ RExC_state_t *pRExC_state, struct regnode_charclass_class *cl) { - int value; - ANYOF_CLASS_ZERO(cl); - for (value = 0; value < 256; ++value) - ANYOF_BITMAP_SET(cl, value); + ANYOF_BITMAP_SETALL(cl); cl->flags = ANYOF_EOS|ANYOF_UNICODE_ALL; if (LOC) cl->flags |= ANYOF_LOCALE; @@ -543,9 +540,8 @@ S_cl_is_anything(pTHX_ struct regnode_charclass_class *cl) return 1; if (!(cl->flags & ANYOF_UNICODE_ALL)) return 0; - for (value = 0; value < 256; ++value) - if (!ANYOF_BITMAP_TEST(cl, value)) - return 0; + if (!ANYOF_BITMAP_TESTALLSET(cl)) + return 0; return 1; } diff --git a/regcomp.h b/regcomp.h index bbe3a41..16cf957 100644 --- a/regcomp.h +++ b/regcomp.h @@ -286,6 +286,14 @@ struct regnode_charclass_class { /* has [[:blah:]] classes */ #define ANYOF_BITMAP_CLEAR(p,c) (ANYOF_BITMAP_BYTE(p, c) &= ~ANYOF_BIT(c)) #define ANYOF_BITMAP_TEST(p, c) (ANYOF_BITMAP_BYTE(p, c) & ANYOF_BIT(c)) +#define ANYOF_BITMAP_SETALL(p) \ + memset (ANYOF_BITMAP(p), 255, ANYOF_BITMAP_SIZE) +#define ANYOF_BITMAP_CLEARALL(p) \ + Zero (ANYOF_BITMAP(p), ANYOF_BITMAP_SIZE) +/* Check that all 256 bits are all set. Used in S_cl_is_anything() */ +#define ANYOF_BITMAP_TESTALLSET(p) \ + memEQ (ANYOF_BITMAP(p), "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377", ANYOF_BITMAP_SIZE) + #define ANYOF_SKIP ((ANYOF_SIZE - 1)/sizeof(regnode)) #define ANYOF_CLASS_SKIP ((ANYOF_CLASS_SIZE - 1)/sizeof(regnode)) #define ANYOF_CLASS_ADD_SKIP (ANYOF_CLASS_SKIP - ANYOF_SKIP)