mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
LibJS: Add simple storage fast path in internal_define_own_property()
...of Array. If array has simple storage, which implies that attributes of all indexed properties are default, and newly added property also has default attribute, we can do a fast path and skip lots of checks that happen in `Object::internal_define_own_property()`.
This commit is contained in:
parent
20655b8ebf
commit
1d4f63e4cd
Notes:
github-actions[bot]
2025-06-05 01:44:42 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 1d4f63e4cd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4997
1 changed files with 15 additions and 1 deletions
|
@ -390,7 +390,21 @@ ThrowCompletionOr<bool> Array::internal_define_own_property(PropertyKey const& p
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// h. Let succeeded be ! OrdinaryDefineOwnProperty(A, P, Desc).
|
// h. Let succeeded be ! OrdinaryDefineOwnProperty(A, P, Desc).
|
||||||
auto succeeded = MUST(Object::internal_define_own_property(property_key, property_descriptor, precomputed_get_own_property));
|
bool succeeded = true;
|
||||||
|
auto* storage = indexed_properties().storage();
|
||||||
|
auto attributes = property_descriptor.attributes();
|
||||||
|
// OPTIMIZATION: Fast path for arrays with simple indexed properties storage.
|
||||||
|
if (property_descriptor.is_data_descriptor() && attributes == default_attributes && storage && storage->is_simple_storage()) {
|
||||||
|
if (!m_is_extensible) {
|
||||||
|
auto existing_descriptor = TRY(internal_get_own_property(property_key));
|
||||||
|
if (!existing_descriptor.has_value())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
storage->put(property_key.as_number(), property_descriptor.value.value());
|
||||||
|
} else {
|
||||||
|
succeeded = MUST(Object::internal_define_own_property(property_key, property_descriptor, precomputed_get_own_property));
|
||||||
|
}
|
||||||
|
|
||||||
// i. If succeeded is false, return false.
|
// i. If succeeded is false, return false.
|
||||||
if (!succeeded)
|
if (!succeeded)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue