diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 4b298b3..a17e035 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -515,6 +515,7 @@ parse_int_string(UC const *p, UC const *pend, T &value, UC const *const start_num = p; + // use SIMD if possible while (p != pend && *p == UC('0')) { ++p; } diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index daf770c..9ef2e87 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -68,7 +68,7 @@ using from_chars_result = from_chars_result_t; template struct parse_options_t { FASTFLOAT_CONSTEXPR20 explicit parse_options_t(chars_format fmt = chars_format::general, - UC dot = UC('.'), unsigned char b = 10) noexcept + UC dot = UC('.'), uint8_t b = 10) noexcept : format(fmt), decimal_point(dot), base(b) {} /** Which number formats are accepted */ @@ -84,7 +84,7 @@ template struct parse_options_t { /** The character used as decimal point */ const UC decimal_point; /** The base used for integers */ - const unsigned char base; + const uint8_t base; /* only allowed from 2 to 36 */ }; using parse_options = parse_options_t; @@ -224,7 +224,7 @@ using parse_options = parse_options_t; namespace fast_float { -fastfloat_really_inline constexpr bool cpp20_and_in_constexpr() noexcept { +fastfloat_really_inline FASTFLOAT_CONSTEVAL20 bool cpp20_and_in_constexpr() noexcept { #if FASTFLOAT_HAS_IS_CONSTANT_EVALUATED return std::is_constant_evaluated(); #else @@ -1024,6 +1024,8 @@ to_float( #endif } +#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN + template struct space_lut { static constexpr bool value[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1049,6 +1051,8 @@ template constexpr bool is_space(UC c) { return c < 256 && space_lut<>::value[uint8_t(c)]; } +#endif + template static constexpr uint64_t int_cmp_zeros() { static_assert((sizeof(UC) == 1) || (sizeof(UC) == 2) || (sizeof(UC) == 4), "Unsupported character size"); diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 0863d00..47f04e8 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -314,12 +314,15 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value, first++; } } -#endif if (first == last) { answer.ec = std::errc::invalid_argument; answer.ptr = first; return answer; } +#else + // We are in parser code with external loop that checks bounds. + [[assume((first < last))]]; +#endif parsed_number_string_t const pns = parse_number_string(first, last, options); if (!pns.valid) { @@ -369,8 +372,15 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value, first++; } } +#else + // We are in parser code with external loop that checks bounds. + [[assume((first < last))]]; #endif - if (first == last || options.base < 2 || options.base > 36) { + if ( +#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN + first == last +#endif + options.base < 2 || options.base > 36) { from_chars_result_t answer; answer.ec = std::errc::invalid_argument; answer.ptr = first;