|
13 | 13 | #ifndef LLVM_LIBC_SRC___SUPPORT_INTEGER_LITERALS_H |
14 | 14 | #define LLVM_LIBC_SRC___SUPPORT_INTEGER_LITERALS_H |
15 | 15 |
|
16 | | -#include "src/__support/CPP/limits.h" // CHAR_BIT |
| 16 | +#include "src/__support/CPP/limits.h" // CHAR_BIT |
| 17 | +#include "src/__support/ctype_utils.h" |
17 | 18 | #include "src/__support/macros/attributes.h" // LIBC_INLINE |
18 | 19 | #include "src/__support/macros/config.h" |
19 | | -#include "src/__support/uint128.h" // UInt128 |
20 | | -#include <stddef.h> // size_t |
21 | | -#include <stdint.h> // uintxx_t |
| 20 | +#include "src/__support/uint128.h" // UInt128 |
| 21 | +#include <stddef.h> // size_t |
| 22 | +#include <stdint.h> // uintxx_t |
22 | 23 |
|
23 | 24 | namespace LIBC_NAMESPACE_DECL { |
24 | 25 |
|
@@ -75,26 +76,13 @@ template <typename T, int base> struct DigitBuffer { |
75 | 76 | push(*str); |
76 | 77 | } |
77 | 78 |
|
78 | | - // Returns the digit for a particular character. |
79 | | - // Returns INVALID_DIGIT if the character is invalid. |
80 | | - LIBC_INLINE static constexpr uint8_t get_digit_value(const char c) { |
81 | | - const auto to_lower = [](char c) { return c | 32; }; |
82 | | - const auto is_digit = [](char c) { return c >= '0' && c <= '9'; }; |
83 | | - const auto is_alpha = [](char c) { |
84 | | - return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); |
85 | | - }; |
86 | | - if (is_digit(c)) |
87 | | - return static_cast<uint8_t>(c - '0'); |
88 | | - if (base > 10 && is_alpha(c)) |
89 | | - return static_cast<uint8_t>(to_lower(c) - 'a' + 10); |
90 | | - return INVALID_DIGIT; |
91 | | - } |
92 | | - |
93 | 79 | // Adds a single character to this buffer. |
94 | 80 | LIBC_INLINE constexpr void push(char c) { |
95 | 81 | if (c == '\'') |
96 | 82 | return; // ' is valid but not taken into account. |
97 | | - const uint8_t value = get_digit_value(c); |
| 83 | + const int b36_val = internal::b36_char_to_int(c); |
| 84 | + const uint8_t value = static_cast<uint8_t>( |
| 85 | + b36_val < base && (b36_val != 0 || c == '0') ? b36_val : INVALID_DIGIT); |
98 | 86 | if (value == INVALID_DIGIT || size >= MAX_DIGITS) { |
99 | 87 | // During constant evaluation `__builtin_unreachable` will halt the |
100 | 88 | // compiler as it is not executable. This is preferable over `assert` that |
|
0 commit comments