Skip to content

Commit d32ae04

Browse files
committed
reduce size of from_chars_result_t to 4 bytes. Cleanup for usage FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN.
1 parent 8d4ca69 commit d32ae04

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

include/fast_float/ascii_number.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ parse_number_string(UC const *p, UC const *pend,
301301
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
302302
answer.negative = (*p == UC('-'));
303303
// C++17 20.19.3.(7.1) explicitly forbids '+' sign here
304-
if ((*p == UC('-')) || (uint64_t(options.format & chars_format::allow_leading_plus) &&
304+
if ((*p == UC('-')) || (uint8_t(options.format & chars_format::allow_leading_plus) &&
305305
!basic_json_fmt && *p == UC('+'))) {
306306
++p;
307307
if (p == pend) {
@@ -385,10 +385,10 @@ parse_number_string(UC const *p, UC const *pend,
385385
}
386386
int32_t exp_number = 0; // explicit exponential part
387387
if (p != pend &&
388-
(uint64_t(options.format & chars_format::scientific) &&
388+
(uint8_t(options.format & chars_format::scientific) &&
389389
((UC('e') == *p) || (UC('E') == *p)))
390390
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
391-
|| (uint64_t(options.format & detail::basic_fortran_fmt) &&
391+
|| (uint8_t(options.format & detail::basic_fortran_fmt) &&
392392
(UC('d') == *p) || (UC('D') == *p))
393393
#endif
394394
) {
@@ -406,7 +406,7 @@ parse_number_string(UC const *p, UC const *pend,
406406
}
407407
}
408408
if ((p == pend) || !is_integer(*p)) {
409-
if (!uint64_t(options.format & chars_format::fixed)) {
409+
if (!uint8_t(options.format & chars_format::fixed)) {
410410
// The exponential part is invalid for scientific notation, so it must
411411
// be a trailing token for fixed notation. However, fixed notation is
412412
// disabled, so report a scientific notation error.
@@ -427,8 +427,8 @@ parse_number_string(UC const *p, UC const *pend,
427427
}
428428
} else {
429429
// If it scientific and not fixed, we have to bail out.
430-
if (uint64_t(options.format & chars_format::scientific) &&
431-
!uint64_t(options.format & chars_format::fixed)) {
430+
if (uint8_t(options.format & chars_format::scientific) &&
431+
!uint8_t(options.format & chars_format::fixed)) {
432432
return report_parse_error<UC>(p, parse_error::missing_exponential_part);
433433
}
434434
}
@@ -510,7 +510,7 @@ parse_int_string(UC const *p, UC const *pend, T &value,
510510
return answer;
511511
}
512512
if ((*p == UC('-')) ||
513-
(uint64_t(options.format & chars_format::allow_leading_plus) &&
513+
(uint8_t(options.format & chars_format::allow_leading_plus) &&
514514
(*p == UC('+')))) {
515515
++p;
516516
}

include/fast_float/fast_float.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ from_chars(UC const *first, UC const *last, T &value,
4343
template <typename T, typename UC = char>
4444
FASTFLOAT_CONSTEXPR20 from_chars_result_t<UC>
4545
from_chars_advanced(UC const *first, UC const *last, T &value,
46-
parse_options_t<UC> const &options) noexcept;
46+
parse_options_t<UC> const options) noexcept;
4747

4848
/**
4949
* from_chars for integer types.

include/fast_float/parse_number.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
310310

311311
from_chars_result_t<UC> answer;
312312
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
313-
if (uint64_t(options.format & chars_format::skip_white_space)) {
313+
if (uint8_t(options.format & chars_format::skip_white_space)) {
314314
while ((first != last) && fast_float::is_space(*first)) {
315315
first++;
316316
}
@@ -326,14 +326,14 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
326326
#endif
327327
parsed_number_string_t<UC> const pns =
328328
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
329-
uint64_t(options.format & detail::basic_json_fmt)
329+
uint8_t(options.format & detail::basic_json_fmt)
330330
? parse_number_string<true, UC>(first, last, options)
331331
:
332332
#endif
333333
parse_number_string<false, UC>(first, last, options);
334334
if (!pns.valid) {
335335
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
336-
if (uint64_t(options.format & chars_format::no_infnan)) {
336+
if (uint8_t(options.format & chars_format::no_infnan)) {
337337
#endif
338338
answer.ec = std::errc::invalid_argument;
339339
answer.ptr = first;
@@ -373,7 +373,7 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
373373
"only char, wchar_t, char16_t and char32_t are supported");
374374

375375
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
376-
if (uint64_t(options.format & chars_format::skip_white_space)) {
376+
if (uint8_t(options.format & chars_format::skip_white_space)) {
377377
while ((first != last) && fast_float::is_space(*first)) {
378378
first++;
379379
}
@@ -387,6 +387,7 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
387387
#else
388388
// We are in parser code with external loop that checks bounds.
389389
FASTFLOAT_ASSUME(first < last);
390+
// base is already checked in the parse_options_t constructor.
390391
#endif
391392

392393
return parse_int_string(first, last, value, options);

0 commit comments

Comments
 (0)