summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2013-11-23 10:04:57 -0700
committerKarl Williamson <public@khwilliamson.com>2013-11-26 21:03:39 -0700
commit14f6cdfdccf676b1c8cfc9f5ad190c3cc2356856 (patch)
treeca3d5bff1dfc28b49a4e9463beb5e7c37bb69b44 /handy.h
parenta2b0867187c3f1dc1866fb63cfd59da300fb4dd5 (diff)
downloadperl-14f6cdfdccf676b1c8cfc9f5ad190c3cc2356856.tar.gz
handy.h: Slightly refactor READ_XDIGIT macro
This adds comments as to how it works, factors out the mask to be specified only once, and uses isDIGIT instead of isALPHA, as the former is likely to be slightly more efficient (because isDIGIT doesn't have to worry about there being non-ASCII digits, and isALPHA does have to worry about non-ASCII alphas). The result is easier to understand what's going on.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/handy.h b/handy.h
index 14faefa663..2ea7a6ec59 100644
--- a/handy.h
+++ b/handy.h
@@ -1553,7 +1553,11 @@ typedef U32 line_t;
} \
return a;
-#define READ_XDIGIT(s) (isALPHA(*(s)) ? ((*(s)++ + 9) & 0xf) : (*(s)++ & 0xf))
+/* Converts a hex digit in a string to its numeric value, advancing the
+ * pointer. The input must be known to be 0-9, A-F, or a-f. In both ASCII and
+ * EBCDIC the last 4 bits of the digits are 0-9; and the last 4 bits of A-F and
+ * a-f are 1-6, so adding 9 yields 10-15 */
+#define READ_XDIGIT(s) (0xf & (isDIGIT(*(s)) ? (*(s)++) : (*(s)++ + 9)))
/*
=head1 Memory Management