summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-12-09 23:41:29 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-10 00:40:52 +0000
commit4cdfe684b819d2b25282cfad156669024bcba511 (patch)
tree1759c5dabae114510b701940e286ecb7984eef66
parent2b55ccf6e5a305d2ae527d455c668668ac474fba (diff)
downloadserenity-4cdfe684b819d2b25282cfad156669024bcba511.zip
LibJS: Remove redundant starts_with()s from is_less_than() string branch
This is not in the spec and does pointless work: - If either of them is true, we would determine the same result with the manual code point iteration and comparison - If neither of them is true, we iterate from the start again and repeat the work that was just done Instead, only have the manual loop from the spec and do a length comparison at the end. Removing it brings the following microbenchmark from ~5.5s down to ~3.5s on my machine: ```js const a = "x".repeat(100_000_000) + "a"; const b = "x".repeat(100_000_000) + "b"; a < b ```
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index 8244f92ef3..159421fcd4 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -1568,11 +1568,6 @@ ThrowCompletionOr<TriState> is_less_than(VM& vm, Value lhs, Value rhs, bool left
Utf8View x_code_points { x_string };
Utf8View y_code_points { y_string };
- if (x_code_points.starts_with(y_code_points))
- return TriState::False;
- if (y_code_points.starts_with(x_code_points))
- return TriState::True;
-
for (auto k = x_code_points.begin(), l = y_code_points.begin();
k != x_code_points.end() && l != y_code_points.end();
++k, ++l) {
@@ -1584,7 +1579,10 @@ ThrowCompletionOr<TriState> is_less_than(VM& vm, Value lhs, Value rhs, bool left
}
}
}
- VERIFY_NOT_REACHED();
+
+ return x_code_points.length() < y_code_points.length()
+ ? TriState::True
+ : TriState::False;
}
if (x_primitive.is_bigint() && y_primitive.is_string()) {