Reduce registers pressure.

This commit is contained in:
IRainman 2025-03-28 18:31:01 +03:00
parent 34df2fc76b
commit 8ebc89e1b5
2 changed files with 13 additions and 11 deletions

View File

@ -294,7 +294,9 @@ template <bool basic_json_fmt, typename UC>
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
parse_number_string(UC const *p, UC const *pend,
parse_options_t<UC> const &options) noexcept {
// V2008 Cyclomatic complexity: 59.
// Consider refactoring the 'parse_number_string' function.
// FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN fix this.
parsed_number_string_t<UC> answer;
answer.valid = false;
answer.too_many_digits = false;
@ -541,7 +543,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
loop_parse_if_eight_digits(p, pend, i); // use SIMD if possible
}
while (p != pend) {
const uint8_t digit = ch_to_digit(*p);
uint8_t const digit = ch_to_digit(*p);
if (digit >= options.base) {
break;
}
@ -550,7 +552,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
p++;
}
size_t digit_count = size_t(p - start_digits);
uint8_t const digit_count = size_t(p - start_digits);
if (digit_count == 0) {
if (has_leading_zeros) {
@ -567,7 +569,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
answer.ptr = p;
// check u64 overflow
size_t const max_digits = max_digits_u64(options.base);
uint8_t const max_digits = max_digits_u64(options.base);
if (digit_count > max_digits) {
answer.ec = std::errc::result_out_of_range;
return answer;

View File

@ -73,11 +73,11 @@ template <typename UC> struct parse_options_t {
: format(fmt), decimal_point(dot), base(static_cast<uint8_t>(b)) {}
/** Which number formats are accepted */
const chars_format format;
chars_format format;
/** The character used as decimal point */
const UC decimal_point;
UC decimal_point;
/** The base used for integers */
const uint8_t base; /* only allowed from 2 to 36 */
uint8_t base; /* only allowed from 2 to 36 */
};
using parse_options = parse_options_t<char>;
@ -1129,7 +1129,7 @@ template <typename = void> struct int_luts {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255};
static constexpr size_t maxdigits_u64[] = {
static constexpr uint8_t maxdigits_u64[] = {
64, 41, 32, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 16, 16, 16, 16,
15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13};
@ -1152,7 +1152,7 @@ template <typename = void> struct int_luts {
template <typename T> constexpr uint8_t int_luts<T>::chdigit[];
template <typename T> constexpr size_t int_luts<T>::maxdigits_u64[];
template <typename T> constexpr uint8_t int_luts<T>::maxdigits_u64[];
template <typename T> constexpr uint64_t int_luts<T>::min_safe_u64[];
@ -1163,13 +1163,13 @@ fastfloat_really_inline constexpr uint8_t ch_to_digit(UC c) {
return int_luts<>::chdigit[static_cast<unsigned char>(c)];
}
fastfloat_really_inline constexpr size_t max_digits_u64(int base) {
fastfloat_really_inline constexpr uint8_t max_digits_u64(uint8_t base) {
return int_luts<>::maxdigits_u64[base - 2];
}
// If a u64 is exactly max_digits_u64() in length, this is
// the value below which it has definitely overflowed.
fastfloat_really_inline constexpr uint64_t min_safe_u64(int base) {
fastfloat_really_inline constexpr uint8_t min_safe_u64(uint8_t base) {
return int_luts<>::min_safe_u64[base - 2];
}