From f06c12173c9e82361165e642d734cf70e428fd63 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 18 May 2020 12:46:39 +0100 Subject: [PATCH] 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. --- Libraries/LibJS/Runtime/GlobalObject.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp index 3ebbb2665f..6cddc07568 100644 --- a/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -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 {};