Slightly less ugly code.

This commit is contained in:
Daniel Lemire 2023-04-26 18:46:19 -04:00
parent 225df8c934
commit 8199baeb70
2 changed files with 34 additions and 4 deletions

View File

@ -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<UC> 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<UC,char>::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;
}
}

View File

@ -201,6 +201,16 @@ bool is_truncated(span<const UC> 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<UC>& num, size_t max_
while (p != pend) {
if (std::is_same<UC,char>::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<UC>& num, size_t max_
while (p != pend) {
if (std::is_same<UC,char>::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) {