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_get_own_property()
...of Array. This allows us to avoid lots of unnecessary for simple arrays checks that happen in `Object::internal_get_own_property()`.
This commit is contained in:
parent
f6f7c69023
commit
20655b8ebf
Notes:
github-actions[bot]
2025-06-05 01:44:49 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 20655b8ebf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4997
1 changed files with 16 additions and 0 deletions
|
@ -276,6 +276,22 @@ ThrowCompletionOr<double> compare_array_elements(VM& vm, Value x, Value y, Funct
|
|||
// NON-STANDARD: Used to return the value of the ephemeral length property
|
||||
ThrowCompletionOr<Optional<PropertyDescriptor>> Array::internal_get_own_property(PropertyKey const& property_key) const
|
||||
{
|
||||
// OPTIMIZATION: Fast path for arrays with simple indexed properties storage.
|
||||
auto const* storage = indexed_properties().storage();
|
||||
if (property_key.is_number() && storage && storage->is_simple_storage()) {
|
||||
auto const& simple_storage = static_cast<SimpleIndexedPropertyStorage const&>(*storage);
|
||||
auto value_and_attributes = simple_storage.get(property_key.as_number());
|
||||
if (value_and_attributes.has_value()) {
|
||||
PropertyDescriptor descriptor;
|
||||
descriptor.value = value_and_attributes->value;
|
||||
descriptor.writable = true;
|
||||
descriptor.enumerable = true;
|
||||
descriptor.configurable = true;
|
||||
return descriptor;
|
||||
}
|
||||
return Optional<PropertyDescriptor> {};
|
||||
}
|
||||
|
||||
auto& vm = this->vm();
|
||||
if (property_key.is_string() && property_key.as_string() == vm.names.length.as_string())
|
||||
return PropertyDescriptor { .value = Value(indexed_properties().array_like_size()), .writable = m_length_writable, .enumerable = false, .configurable = false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue