do not convert to stdString expensively when parsing ordered json numbers

This commit is contained in:
garak 2023-01-09 11:38:42 -05:00 committed by t
parent 4df4e6ddd7
commit f1b962bdf5

View file

@ -631,7 +631,8 @@ struct JsonParser final {
if (str[i] != '.' && str[i] != 'e' && str[i] != 'E'
&& (i - start_pos) <= static_cast<unsigned>(std::numeric_limits<int>::digits10)) {
return std::atoi(str.toStdString().c_str() + start_pos);
bool ok;
return str.mid(start_pos, i - start_pos).toInt(&ok);
}
// Decimal part
@ -658,7 +659,8 @@ struct JsonParser final {
i++;
}
return std::strtod(str.toStdString().c_str() + start_pos, nullptr);
bool ok;
return str.mid(start_pos, i - start_pos).toDouble(&ok);
}
/* expect(str, res)