Introduces fast path for integers.

This commit is contained in:
Daniel Lemire 2020-11-09 18:57:03 -05:00
parent 8ea46c6155
commit ccecd5048a

View File

@ -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<T>::min_exponent_fast_path() <= pns.exponent && pns.exponent <= binary_format<T>::max_exponent_fast_path() && pns.mantissa <=binary_format<T>::max_mantissa_fast_path()) {
value = T(pns.mantissa);
if (pns.exponent < 0) { value = value / binary_format<T>::exact_power_of_ten(-pns.exponent); }