Skip to content

Commit ebc2ee8

Browse files
committed
optimization for the report_parse_error.
1 parent 054004f commit ebc2ee8

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

include/fast_float/ascii_number.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ using parsed_number_string = parsed_number_string_t<char>;
277277

278278
template <typename UC>
279279
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 parsed_number_string_t<UC>
280-
report_parse_error(UC const *p, parse_error error) noexcept {
281-
parsed_number_string_t<UC> answer;
280+
report_parse_error(parsed_number_string_t<UC> &answer, UC const *p,
281+
parse_error error) noexcept {
282282
answer.invalid = true;
283283
answer.lastmatch = p;
284284
answer.error = error;
@@ -303,20 +303,20 @@ parse_number_string(UC const *p, UC const *pend,
303303
++p;
304304
if (p == pend) {
305305
return report_parse_error<UC>(
306-
p, parse_error::missing_integer_or_dot_after_sign);
306+
answer, p, parse_error::missing_integer_or_dot_after_sign);
307307
}
308308
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
309309
// a sign must be followed by an integer
310310
if (!is_integer(*p)) {
311-
return report_parse_error<UC>(p,
311+
return report_parse_error<UC>(answer, p,
312312
parse_error::missing_integer_after_sign);
313313
}
314314
}
315315
else {
316316
// a sign must be followed by an integer or the dot
317317
if (!is_integer(*p) && (*p != options.decimal_point)) {
318318
return report_parse_error<UC>(
319-
p, parse_error::missing_integer_or_dot_after_sign);
319+
answer, p, parse_error::missing_integer_or_dot_after_sign);
320320
}
321321
}
322322
}
@@ -343,10 +343,11 @@ parse_number_string(UC const *p, UC const *pend,
343343
FASTFLOAT_IF_CONSTEXPR17(basic_json_fmt) {
344344
// at least 1 digit in integer part, without leading zeros
345345
if (digit_count == 0) {
346-
return report_parse_error<UC>(p, parse_error::no_digits_in_integer_part);
346+
return report_parse_error<UC>(answer, p,
347+
parse_error::no_digits_in_integer_part);
347348
}
348349
if ((start_digits[0] == UC('0') && digit_count > 1)) {
349-
return report_parse_error<UC>(start_digits,
350+
return report_parse_error<UC>(answer, start_digits,
350351
parse_error::leading_zeros_in_integer_part);
351352
}
352353
}
@@ -376,13 +377,14 @@ parse_number_string(UC const *p, UC const *pend,
376377
// at least 1 digit in fractional part
377378
if (answer.exponent == 0) {
378379
return report_parse_error<UC>(
379-
p, parse_error::no_digits_in_fractional_part);
380+
answer, p, parse_error::no_digits_in_fractional_part);
380381
}
381382
}
382383
#endif
383384
} else if (digit_count == 0) {
384385
// We must have encountered at least one integer!
385-
return report_parse_error<UC>(p, parse_error::no_digits_in_mantissa);
386+
return report_parse_error<UC>(answer, p,
387+
parse_error::no_digits_in_mantissa);
386388
}
387389
// We have now parsed the integer and the fraction part of the mantissa.
388390

@@ -425,7 +427,8 @@ parse_number_string(UC const *p, UC const *pend,
425427
// The exponential part is invalid for scientific notation, so it
426428
// must be a trailing token for fixed notation. However, fixed
427429
// notation is disabled, so report a scientific notation error.
428-
return report_parse_error<UC>(p, parse_error::missing_exponential_part);
430+
return report_parse_error<UC>(answer, p,
431+
parse_error::missing_exponential_part);
429432
}
430433
// Otherwise, we will be ignoring the 'e'.
431434
p = location_of_e;
@@ -448,7 +451,8 @@ parse_number_string(UC const *p, UC const *pend,
448451
// If it scientific and not fixed, we have to bail out.
449452
if ((chars_format_t(options.format & chars_format::scientific)) &&
450453
!(chars_format_t(options.format & chars_format::fixed))) {
451-
return report_parse_error<UC>(p, parse_error::missing_exponential_part);
454+
return report_parse_error<UC>(answer, p,
455+
parse_error::missing_exponential_part);
452456
}
453457
}
454458

0 commit comments

Comments
 (0)