1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-07 21:17:07 +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:
Aliaksandr Kalenik 2025-06-04 17:01:02 +02:00 committed by Alexander Kalenik
parent 20655b8ebf
commit 1d4f63e4cd
Notes: github-actions[bot] 2025-06-05 01:44:42 +00:00

View file

@ -390,7 +390,21 @@ ThrowCompletionOr<bool> Array::internal_define_own_property(PropertyKey const& p
return false;
// 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.
if (!succeeded)