Commit 8d18a191 authored by Balaram Makam's avatar Balaram Makam Committed by Commit Bot

[intl] Early return for identical and empty strings.

When one of two compared strings is empty, or when both
are the same object, we can skip the calls to Flatten
and into ICU.

Performance results on hikey620(cortex-a53) device:
Speedometer2.0 - no impact.
Jetstream2.0 - only impacts CDJS subtest:

name  old score  new score  delta
CDJS  2.33 ± 3%  2.38 ± 1%  +2.35%  (p=0.009 n=6+5)

Change-Id: Ibe490f86188caab1d7712b52c610658e1e2b819c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1584221
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61305}
parent 3c510438
......@@ -993,6 +993,21 @@ Handle<Object> Intl::CompareStrings(Isolate* isolate,
Handle<String> string2) {
Factory* factory = isolate->factory();
// Early return for identical strings.
if (string1.is_identical_to(string2)) {
return factory->NewNumberFromInt(UCollationResult::UCOL_EQUAL);
}
// Early return for empty strings.
if (string1->length() == 0) {
return factory->NewNumberFromInt(string2->length() == 0
? UCollationResult::UCOL_EQUAL
: UCollationResult::UCOL_LESS);
}
if (string2->length() == 0) {
return factory->NewNumberFromInt(UCollationResult::UCOL_GREATER);
}
string1 = String::Flatten(isolate, string1);
string2 = String::Flatten(isolate, string2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment