mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibJS: Add a localCompare() fast path for identical strings
When identical strings use the default collator, a simple equality check can be used.
This commit is contained in:
parent
010b0b00ff
commit
f268458aa4
Notes:
github-actions[bot]
2025-11-23 23:23:25 +00:00
Author: https://github.com/tcl3
Commit: f268458aa4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6915
Reviewed-by: https://github.com/gmta ✅
1 changed files with 6 additions and 2 deletions
|
|
@ -568,10 +568,14 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::locale_compare)
|
|||
|
||||
// OPTIMIZATION: If both locales and options are undefined, we can use a cached default-constructed Collator.
|
||||
GC::Ptr<Object> collator;
|
||||
if (locales.is_undefined() && options.is_undefined())
|
||||
if (locales.is_undefined() && options.is_undefined()) {
|
||||
// OPTIMIZATION: Identical strings are equal with the default options.
|
||||
if (string == that_value)
|
||||
return Value(0);
|
||||
collator = realm.intrinsics().default_collator();
|
||||
else
|
||||
} else {
|
||||
collator = TRY(construct(vm, realm.intrinsics().intl_collator_constructor(), locales, options));
|
||||
}
|
||||
|
||||
// 5. Return CompareStrings(collator, S, thatValue).
|
||||
return Intl::compare_strings(static_cast<Intl::Collator const&>(*collator), string, that_value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue