LibJS: Return early from parseFloat() if argument is a number

This saves us both a bit of time and accuracy, as Serenity's strtod()
still is a little bit off sometimes - and stringifying the result and
parsing it again just increases that offset.
This commit is contained in:
Linus Groh 2020-05-18 12:46:39 +01:00 committed by Andreas Kling
parent 088841202d
commit f06c12173c
Notes: sideshowbarker 2024-07-19 06:31:30 +09:00

View File

@ -153,6 +153,8 @@ Value GlobalObject::is_finite(Interpreter& interpreter)
Value GlobalObject::parse_float(Interpreter& interpreter)
{
if (interpreter.argument(0).is_number())
return interpreter.argument(0);
auto string = interpreter.argument(0).to_string(interpreter);
if (interpreter.exception())
return {};