summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2011-09-24 11:46:54 -0600
committerKarl Williamson <public@khwilliamson.com>2011-10-01 09:58:08 -0600
commit41f43cc22340d382ce3bf1249a2521a4ec5285a8 (patch)
tree68fa65c0680e3806dad51c802ca6d3fc98b58d34 /handy.h
parent7c06269796e51fcf84efa5f5dab9ed98447ef9c1 (diff)
downloadperl-41f43cc22340d382ce3bf1249a2521a4ec5285a8.tar.gz
handy.h: Simplify isASCII definition
Thus retains essentially the same definition for EBCDIC platforms, but substitutes a simpler one for ASCII platforms. On my system, the new definition compiles to about half the assembly instructions that the old one did (non-optimized) A bomb-proof definition of ASCII is to make sure that the value is unsigned in the largest possible unsigned for the platform so there is no possible loss of information, and then the ord must be < 128.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/handy.h b/handy.h
index 5f0bdd3e46..1f78e963a4 100644
--- a/handy.h
+++ b/handy.h
@@ -582,7 +582,12 @@ patched there. The file as of this writing is cpan/Devel-PPPort/parts/inc/misc
#define FITS_IN_8_BITS(c) ((sizeof(c) == 1) \
|| (((WIDEST_UTYPE)(c) & 0xFF) == (WIDEST_UTYPE)(c)))
-#define isASCII(c) (FITS_IN_8_BITS(c) ? NATIVE_TO_UNI((U8) c) <= 127 : 0)
+#ifdef EBCDIC
+# define isASCII(c) (FITS_IN_8_BITS(c) ? NATIVE_TO_UNI((U8) (c)) < 128 : 0)
+#else
+# define isASCII(c) ((WIDEST_UTYPE)(c) < 128)
+#endif
+
#define isASCII_A(c) isASCII(c)
/* ASCII range only */