mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-11 03:56:16 +00:00
LibJS: Cache the Intl.Collator in String.prototype.localeCompare()
In the very common case that no special constructor options are provided for the Intl.Collator when calling localeCompare() on a string, we can cache and reuse a default-constructed Intl.Collator, saving lots of time and space. This shaves a fair bit of load time off of https://wpt.fyi/ where they use Array.prototype.sort() and localeCompare() to sort a big JSON thing. Time spent in sort(): - Before: 1656 ms - After: 135 ms
This commit is contained in:
parent
65c1c492f9
commit
d465e2aa2b
Notes:
github-actions[bot]
2025-01-23 20:39:21 +00:00
Author: https://github.com/awesomekling
Commit: d465e2aa2b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3347
3 changed files with 26 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2020-2025, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -95,6 +96,8 @@ public:
|
|||
JS_ENUMERATE_ITERATOR_PROTOTYPES
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
[[nodiscard]] GC::Ref<Intl::Collator> default_collator();
|
||||
|
||||
private:
|
||||
Intrinsics(Realm& realm)
|
||||
: m_realm(realm)
|
||||
|
@ -189,6 +192,8 @@ private:
|
|||
GC::Ptr<Object> m_##snake_name##_prototype;
|
||||
JS_ENUMERATE_ITERATOR_PROTOTYPES
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
GC::Ptr<Intl::Collator> m_default_collator;
|
||||
};
|
||||
|
||||
void add_restricted_function_properties(FunctionObject&, Realm&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue