mirror of
https://github.com/zebrajr/ladybird.git
synced 2026-01-15 12:15:15 +00: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:
committed by
Alexander Kalenik
parent
20655b8ebf
commit
1d4f63e4cd
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user