From 8199baeb7075bf7642834c388ffd1a3d5a980011 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 26 Apr 2023 18:46:19 -0400 Subject: [PATCH] Slightly less ugly code. --- include/fast_float/ascii_number.h | 24 ++++++++++++++++++++++-- include/fast_float/digit_comparison.h | 14 ++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 98365e2..d506326 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -76,6 +76,16 @@ uint32_t parse_eight_digits_unrolled(uint64_t val) { return uint32_t(val); } +fastfloat_really_inline constexpr +uint32_t parse_eight_digits_unrolled(const char16_t *) noexcept { + return 0; +} + +fastfloat_really_inline constexpr +uint32_t parse_eight_digits_unrolled(const char32_t *) noexcept { + return 0; +} + fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint32_t parse_eight_digits_unrolled(const char *chars) noexcept { return parse_eight_digits_unrolled(read_u64(chars)); @@ -87,6 +97,16 @@ fastfloat_really_inline constexpr bool is_made_of_eight_digits_fast(uint64_t val 0x8080808080808080)); } +fastfloat_really_inline constexpr +bool is_made_of_eight_digits_fast(const char16_t *) noexcept { + return false; +} + +fastfloat_really_inline constexpr +bool is_made_of_eight_digits_fast(const char32_t *) noexcept { + return false; +} + fastfloat_really_inline FASTFLOAT_CONSTEXPR20 bool is_made_of_eight_digits_fast(const char *chars) noexcept { return is_made_of_eight_digits_fast(read_u64(chars)); @@ -152,8 +172,8 @@ parsed_number_string_t parse_number_string(UC const *p, UC const * pend, par // can occur at most twice without overflowing, but let it occur more, since // for integers with many digits, digit parsing is the primary bottleneck. if (std::is_same::value) { - while ((std::distance(p, pend) >= 8) && is_made_of_eight_digits_fast((const char *&)p)) { - i = i * 100000000 + parse_eight_digits_unrolled((const char *&)p); // in rare cases, this will overflow, but that's ok + while ((std::distance(p, pend) >= 8) && is_made_of_eight_digits_fast(p)) { + i = i * 100000000 + parse_eight_digits_unrolled(p); // in rare cases, this will overflow, but that's ok p += 8; } } diff --git a/include/fast_float/digit_comparison.h b/include/fast_float/digit_comparison.h index b2c8495..f469f6b 100644 --- a/include/fast_float/digit_comparison.h +++ b/include/fast_float/digit_comparison.h @@ -201,6 +201,16 @@ bool is_truncated(span s) noexcept { return is_truncated(s.ptr, s.ptr + s.len()); } +fastfloat_really_inline FASTFLOAT_CONSTEXPR20 +void parse_eight_digits(const char16_t*& , limb& , size_t& , size_t& ) noexcept { + // currently unused +} + +fastfloat_really_inline FASTFLOAT_CONSTEXPR20 +void parse_eight_digits(const char32_t*& , limb& , size_t& , size_t& ) noexcept { + // currently unused +} + fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void parse_eight_digits(const char*& p, limb& value, size_t& counter, size_t& count) noexcept { value = value * 100000000 + parse_eight_digits_unrolled(p); @@ -256,7 +266,7 @@ void parse_mantissa(bigint& result, parsed_number_string_t& num, size_t max_ while (p != pend) { if (std::is_same::value) { while ((std::distance(p, pend) >= 8) && (step - counter >= 8) && (max_digits - digits >= 8)) { - parse_eight_digits((const char *&)p, value, counter, digits); + parse_eight_digits(p, value, counter, digits); } } while (counter < step && p != pend && digits < max_digits) { @@ -291,7 +301,7 @@ void parse_mantissa(bigint& result, parsed_number_string_t& num, size_t max_ while (p != pend) { if (std::is_same::value) { while ((std::distance(p, pend) >= 8) && (step - counter >= 8) && (max_digits - digits >= 8)) { - parse_eight_digits((const char *&)p, value, counter, digits); + parse_eight_digits(p, value, counter, digits); } } while (counter < step && p != pend && digits < max_digits) {