reduce size of from_chars_result_t to 4 bytes. Cleanup for usage FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN.

This commit is contained in:
IRainman 2025-04-09 15:22:10 +03:00
parent a591ca2fb8
commit 7c96e3a8be
3 changed files with 23 additions and 23 deletions

View File

@ -582,7 +582,9 @@ parse_int_string(UC const *p, UC const *pend, T &value,
} }
} }
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
value = T(i);
#else
if (negative) { if (negative) {
#ifdef FASTFLOAT_VISUAL_STUDIO #ifdef FASTFLOAT_VISUAL_STUDIO
#pragma warning(push) #pragma warning(push)
@ -600,9 +602,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
#pragma warning(pop) #pragma warning(pop)
#endif #endif
} else { } else {
#endif
value = T(i); value = T(i);
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
} }
#endif #endif

View File

@ -33,29 +33,29 @@
namespace fast_float { namespace fast_float {
enum class chars_format : uint64_t; enum class chars_format : uint8_t;
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
namespace detail { namespace detail {
constexpr chars_format basic_json_fmt = chars_format(1 << 5); constexpr chars_format basic_json_fmt = chars_format(1 << 4);
constexpr chars_format basic_fortran_fmt = chars_format(1 << 6); constexpr chars_format basic_fortran_fmt = chars_format(1 << 5);
} // namespace detail } // namespace detail
#endif #endif
enum class chars_format : uint64_t { enum class chars_format : uint8_t {
scientific = 1 << 0, scientific = 1 << 0,
fixed = 1 << 2, fixed = 1 << 1,
general = fixed | scientific, general = fixed | scientific,
hex = 1 << 3, hex = 1 << 2,
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
no_infnan = 1 << 4, no_infnan = 1 << 3,
// RFC 8259: https://datatracker.ietf.org/doc/html/rfc8259#section-6 // RFC 8259: https://datatracker.ietf.org/doc/html/rfc8259#section-6
json = uint64_t(detail::basic_json_fmt) | general | no_infnan, json = uint64_t(detail::basic_json_fmt) | general | no_infnan,
// Extension of RFC 8259 where, e.g., "inf" and "nan" are allowed. // Extension of RFC 8259 where, e.g., "inf" and "nan" are allowed.
json_or_infnan = uint64_t(detail::basic_json_fmt) | general, json_or_infnan = uint64_t(detail::basic_json_fmt) | general,
fortran = uint64_t(detail::basic_fortran_fmt) | general, fortran = uint64_t(detail::basic_fortran_fmt) | general,
allow_leading_plus = 1 << 7, allow_leading_plus = 1 << 6,
skip_white_space = 1 << 8, skip_white_space = 1 << 7,
#endif #endif
}; };
@ -70,14 +70,18 @@ template <typename UC> struct parse_options_t {
FASTFLOAT_CONSTEXPR20 explicit parse_options_t( FASTFLOAT_CONSTEXPR20 explicit parse_options_t(
chars_format fmt = chars_format::general, UC dot = UC('.'), chars_format fmt = chars_format::general, UC dot = UC('.'),
int const b = 10) noexcept int const b = 10) noexcept
: format(fmt), decimal_point(dot), base(b) {} : format(fmt), decimal_point(dot), base(uint8_t(b)) {
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
assert(b >= 2 && b <= 36);
#endif
}
/** Which number formats are accepted */ /** Which number formats are accepted */
chars_format format; chars_format format;
/** The character used as decimal point */ /** The character used as decimal point */
UC decimal_point; UC decimal_point;
/** The base used for integers */ /** The base used for integers */
uint32_t base; /* only allowed from 2 to 36 */ uint8_t base; /* only allowed from 2 to 36 */
FASTFLOAT_ASSUME(base >= 2 && base <= 36); FASTFLOAT_ASSUME(base >= 2 && base <= 36);
}; };

View File

@ -378,20 +378,16 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
first++; first++;
} }
} }
#else if (first == last || options.base < 2 || options.base > 36) {
// We are in parser code with external loop that checks bounds.
FASTFLOAT_ASSUME(first < last);
#endif
if (
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
first == last ||
#endif
options.base < 2 || options.base > 36) {
from_chars_result_t<UC> answer; from_chars_result_t<UC> answer;
answer.ec = std::errc::invalid_argument; answer.ec = std::errc::invalid_argument;
answer.ptr = first; answer.ptr = first;
return answer; return answer;
} }
#else
// We are in parser code with external loop that checks bounds.
FASTFLOAT_ASSUME(first < last);
#endif
return parse_int_string(first, last, value, options); return parse_int_string(first, last, value, options);
} }