summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Value.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-10-25 14:34:22 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-25 14:35:23 +0200
commitb63d17e2f85cacd3fcc98539e28f31647f974ccf (patch)
tree11a5901023812a77a4c977aa148230e41209ef0c /Userland/Libraries/LibJS/Runtime/Value.cpp
parentb4c0e27d267955e747792e55b71b222c9dc27f5a (diff)
downloadserenity-b63d17e2f85cacd3fcc98539e28f31647f974ccf.zip
LibJS: Add fast paths for <, >, <=, and >= with Int32 on both sides
This gives us a ~5% speed-up on Kraken's ai-astar.js
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Value.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index 9e7275bb30..129c286387 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -773,6 +773,9 @@ ThrowCompletionOr<FunctionObject*> Value::get_method(GlobalObject& global_object
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
ThrowCompletionOr<Value> greater_than(GlobalObject& global_object, Value lhs, Value rhs)
{
+ if (lhs.type() == Value::Type::Int32 && rhs.type() == Value::Type::Int32)
+ return lhs.as_i32() > rhs.as_i32();
+
TriState relation = TRY(is_less_than(global_object, false, lhs, rhs));
if (relation == TriState::Unknown)
return Value(false);
@@ -782,6 +785,9 @@ ThrowCompletionOr<Value> greater_than(GlobalObject& global_object, Value lhs, Va
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
ThrowCompletionOr<Value> greater_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
{
+ if (lhs.type() == Value::Type::Int32 && rhs.type() == Value::Type::Int32)
+ return lhs.as_i32() >= rhs.as_i32();
+
TriState relation = TRY(is_less_than(global_object, true, lhs, rhs));
if (relation == TriState::Unknown || relation == TriState::True)
return Value(false);
@@ -791,6 +797,9 @@ ThrowCompletionOr<Value> greater_than_equals(GlobalObject& global_object, Value
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
ThrowCompletionOr<Value> less_than(GlobalObject& global_object, Value lhs, Value rhs)
{
+ if (lhs.type() == Value::Type::Int32 && rhs.type() == Value::Type::Int32)
+ return lhs.as_i32() < rhs.as_i32();
+
TriState relation = TRY(is_less_than(global_object, true, lhs, rhs));
if (relation == TriState::Unknown)
return Value(false);
@@ -800,6 +809,9 @@ ThrowCompletionOr<Value> less_than(GlobalObject& global_object, Value lhs, Value
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
ThrowCompletionOr<Value> less_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
{
+ if (lhs.type() == Value::Type::Int32 && rhs.type() == Value::Type::Int32)
+ return lhs.as_i32() <= rhs.as_i32();
+
TriState relation = TRY(is_less_than(global_object, false, lhs, rhs));
if (relation == TriState::Unknown || relation == TriState::True)
return Value(false);