From ccecd5048a4fff271f8a9e0700dcc3848a890e0c Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Mon, 9 Nov 2020 18:57:03 -0500 Subject: [PATCH] Introduces fast path for integers. --- include/fast_float/parse_number.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index 3e246d9..714b054 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -91,7 +91,12 @@ from_chars_result from_chars(const char *first, const char *last, } answer.ec = std::errc(); // be optimistic answer.ptr = pns.lastmatch; - + // Special fast path for integers. + if((pns.exponent == 0) && !pns.too_many_digits) { + value = T(pns.mantissa); + if (pns.negative) { value = -value; } + return answer; + } if (binary_format::min_exponent_fast_path() <= pns.exponent && pns.exponent <= binary_format::max_exponent_fast_path() && pns.mantissa <=binary_format::max_mantissa_fast_path()) { value = T(pns.mantissa); if (pns.exponent < 0) { value = value / binary_format::exact_power_of_ten(-pns.exponent); }