diff options
author | Karl Williamson <public@khwilliamson.com> | 2010-09-23 21:04:58 -0600 |
---|---|---|
committer | Steffen Mueller <smueller@cpan.org> | 2010-09-25 11:15:31 +0200 |
commit | 25d1bb793c74dbeadfb79bec17165e4c3970f3ba (patch) | |
tree | 80bd88e03c83d7b063eb1a31dee5909330b6b337 /handy.h | |
parent | 9c68f0abf07d540a547ec774305849d8cf1f3dfe (diff) | |
download | perl-25d1bb793c74dbeadfb79bec17165e4c3970f3ba.tar.gz |
handy.h: Change isFOO_A() to be O(1) performance
This patch changes the macros whose names end in _A to use table lookup
except for the one (isASCII) which always has only one comparison.
The table is in l1_char_class_tab.h.
The advantage of this is speed. It replaces some fairly complicated
expressions with an O(1) look-up and a mask.
It uses the FITS_IN_8_BITS() macro to guarantee that the table bounds
are not exceeded. For legal inputs that are byte size, the optimizer
should get rid of this macro leaving only the lookup and mask.
(This commit was changed from its original form by Steffen.)
Diffstat (limited to 'handy.h')
-rw-r--r-- | handy.h | 49 |
1 files changed, 17 insertions, 32 deletions
@@ -513,39 +513,24 @@ patched there. The file as of this writing is cpan/Devel-PPPort/parts/inc/misc #define isASCII(c) (FITS_IN_8_BITS(c) ? NATIVE_TO_UNI((U8) c) <= 127 : 0) #define isASCII_A(c) isASCII(c) +/* include the Latin1 lookup table */ +#include "l1_char_class_tab.h" + /* ASCII range only */ -#ifdef EBCDIC -# define isALNUMC_A(c) (isASCII(c) && isALNUMC(c)) -# define isALPHA_A(c) (isASCII(c) && isALPHA(c)) -# define isBLANK_A(c) (isASCII(c) && isBLANK(c)) -# define isCNTRL_A(c) (isASCII(c) && isCNTRL(c)) -# define isDIGIT_A(c) (isASCII(c) && isDIGIT(c)) -# define isGRAPH_A(c) (isASCII(c) && isGRAPH(c)) -# define isLOWER_A(c) (isASCII(c) && isLOWER(c)) -# define isPRINT_A(c) (isASCII(c) && isPRINT(c)) -# define isPSXSPC_A(c) (isASCII(c) && isPSXSPC(c)) -# define isPUNCT_A(c) (isASCII(c) && isPUNCT(c)) -# define isSPACE_A(c) (isASCII(c) && isSPACE(c)) -# define isUPPER_A(c) (isASCII(c) && isUPPER(c)) -# define isWORDCHAR_A(c) (isASCII(c) && isWORDCHAR(c)) -# define isXDIGIT_A(c) (isASCII(c) && isXDIGIT(c)) -#else /* ASCII */ -# define isALNUMC_A(c) (isALPHA_A(c) || isDIGIT_A(c)) -# define isALPHA_A(c) (isUPPER_A(c) || isLOWER_A(c)) -# define isBLANK_A(c) ((c) == ' ' || (c) == '\t') -# define isCNTRL_A(c) (FITS_IN_8_BITS(c) ? ((U8) (c) < ' ' || (c) == 127) : 0) -# define isDIGIT_A(c) ((c) >= '0' && (c) <= '9') -# define isGRAPH_A(c) (isWORDCHAR_A(c) || isPUNCT_A(c)) -# define isLOWER_A(c) ((c) >= 'a' && (c) <= 'z') -# define isPRINT_A(c) (((c) >= 32 && (c) < 127)) -# define isPSXSPC_A(c) (isSPACE_A(c) || (c) == '\v') -# define isPUNCT_A(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) -# define isSPACE_A(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) =='\r' \ - || (c) == '\f') -# define isUPPER_A(c) ((c) >= 'A' && (c) <= 'Z') -# define isWORDCHAR_A(c) (isALPHA_A(c) || isDIGIT_A(c) || (c) == '_') -# define isXDIGIT_A(c) (isDIGIT_A(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) -#endif +#define isALNUMC_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_ALNUMC_A)) +#define isALPHA_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_ALPHA_A)) +#define isBLANK_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_BLANK_A)) +#define isCNTRL_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_CNTRL_A)) +#define isDIGIT_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_DIGIT_A)) +#define isGRAPH_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_GRAPH_A)) +#define isLOWER_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_LOWER_A)) +#define isPRINT_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_PRINT_A)) +#define isPSXSPC_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_PSXSPC_A)) +#define isPUNCT_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_PUNCT_A)) +#define isSPACE_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_SPACE_A)) +#define isUPPER_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_UPPER_A)) +#define isWORDCHAR_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_WORDCHAR_A)) +#define isXDIGIT_A(c) cBOOL(FITS_IN_8_BITS(c) && (PL_charclass[(U8) NATIVE_TO_UNI(c)] & _CC_XDIGIT_A)) /* Latin1 definitions */ /* ALPHAU includes Unicode semantics for latin1 characters. It has an extra |