diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/include/llvm/ADT/StringExtras.h @@ -66,10 +66,39 @@ /// /// If \p C is not a valid hex digit, -1U is returned. inline unsigned hexDigitValue(char C) { - if (C >= '0' && C <= '9') return C-'0'; - if (C >= 'a' && C <= 'f') return C-'a'+10U; - if (C >= 'A' && C <= 'F') return C-'A'+10U; - return -1U; + // clang-format off + static unsigned LUT[255] = { + /// 0-47: Non hexadecimal digits + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, + /// 48-57: `0`-`9` hexadecimal digits + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + /// 58-64: Non hexadecimal digits + -1U, -1U, -1U, -1U, -1U, -1U, -1U, + /// 65-70: `A`-`F` hexadecimal digits + 10, 11, 12, 13, 14, 15, + /// 71-96: Non hexadecimal digits + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + /// 97-102: `a`-`f` hexadecimal digits + 10, 11, 12, 13, 14, 15, + /// 103-255: Non hexadecimal digits + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, + -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U, -1U + }; + // clang-format on + return LUT[static_cast(C)]; } /// Checks if character \p C is one of the 10 decimal digits.