From 8ebc89e1b5f9a9094296ae477bfd3f113260a292 Mon Sep 17 00:00:00 2001 From: IRainman Date: Fri, 28 Mar 2025 18:31:01 +0300 Subject: [PATCH] Reduce registers pressure. --- include/fast_float/ascii_number.h | 10 ++++++---- include/fast_float/float_common.h | 14 +++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 30c7e16..83f9e1d 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -294,7 +294,9 @@ template fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t parse_number_string(UC const *p, UC const *pend, parse_options_t 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 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; diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 84f076f..0a03a3a 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -73,11 +73,11 @@ template struct parse_options_t { : format(fmt), decimal_point(dot), base(static_cast(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; @@ -1129,7 +1129,7 @@ template 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 struct int_luts { template constexpr uint8_t int_luts::chdigit[]; -template constexpr size_t int_luts::maxdigits_u64[]; +template constexpr uint8_t int_luts::maxdigits_u64[]; template constexpr uint64_t int_luts::min_safe_u64[]; @@ -1163,13 +1163,13 @@ fastfloat_really_inline constexpr uint8_t ch_to_digit(UC c) { return int_luts<>::chdigit[static_cast(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]; }