summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-05-18 12:46:39 +0100
committerAndreas Kling <kling@serenityos.org>2020-05-18 14:33:53 +0200
commitf06c12173c9e82361165e642d734cf70e428fd63 (patch)
treef5b1c436d97c41ad44398688bf1d98e9f7ce39bf /Libraries
parent088841202d8b29151015a26c65547a9b00c5e901 (diff)
downloadserenity-f06c12173c9e82361165e642d734cf70e428fd63.zip
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.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Runtime/GlobalObject.cpp2
1 files changed, 2 insertions, 0 deletions
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 {};