From 128a96186903c56c5e12c25d8cac89d16e36b78f Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 8 Nov 2016 23:12:02 +0100 Subject: [PATCH] simpler char-to-hexdigit conversion func (can assume because of isxdigit) --- src/cs_util.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/cs_util.cc b/src/cs_util.cc index d08537c..2b12891 100644 --- a/src/cs_util.cc +++ b/src/cs_util.cc @@ -21,17 +21,15 @@ static inline void p_set_end( *end = v; } +/* this function assumes the input is definitely a hex digit */ static inline CsInt p_hexd_to_int(char c) { - if ((c >= 48) && (c <= 57)) { /* 0-9 */ - return c - '0'; - } - if ((c >= 65) && (c <= 70)) { /* A-F */ + if (c >= 97) { /* a-f */ + return (c - 'a') + 10; + } else if (c >= 65) { /* A-F */ return (c - 'A') + 10; } - if ((c >= 97) && (c <= 102)) { /* a-f */ - return (c - 'a') + 10; - } - return 0; + /* 0-9 */ + return c - '0'; } static inline bool p_check_neg(ostd::ConstCharRange &input) {