mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 21:29:06 +00:00
LibJS/Bytecode: Inline indexed property access in GetByVal better
This commit is contained in:
parent
3170ad2ee3
commit
161298b5d1
Notes:
sideshowbarker
2024-07-17 03:16:02 +09:00
Author: https://github.com/awesomekling
Commit: 161298b5d1
Pull-request: https://github.com/SerenityOS/serenity/pull/24260
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/mattco98
3 changed files with 20 additions and 5 deletions
|
@ -168,7 +168,12 @@ inline ThrowCompletionOr<Value> get_by_value(VM& vm, Optional<DeprecatedFlyStrin
|
||||||
// For "non-typed arrays":
|
// For "non-typed arrays":
|
||||||
if (!object.may_interfere_with_indexed_property_access()
|
if (!object.may_interfere_with_indexed_property_access()
|
||||||
&& object_storage) {
|
&& object_storage) {
|
||||||
auto maybe_value = object_storage->get(index);
|
auto maybe_value = [&] {
|
||||||
|
if (object_storage->is_simple_storage())
|
||||||
|
return static_cast<SimpleIndexedPropertyStorage const*>(object_storage)->inline_get(index);
|
||||||
|
else
|
||||||
|
return static_cast<GenericIndexedPropertyStorage const*>(object_storage)->get(index);
|
||||||
|
}();
|
||||||
if (maybe_value.has_value()) {
|
if (maybe_value.has_value()) {
|
||||||
auto value = maybe_value->value;
|
auto value = maybe_value->value;
|
||||||
if (!value.is_accessor())
|
if (!value.is_accessor())
|
||||||
|
|
|
@ -22,14 +22,12 @@ SimpleIndexedPropertyStorage::SimpleIndexedPropertyStorage(Vector<Value>&& initi
|
||||||
|
|
||||||
bool SimpleIndexedPropertyStorage::has_index(u32 index) const
|
bool SimpleIndexedPropertyStorage::has_index(u32 index) const
|
||||||
{
|
{
|
||||||
return index < m_array_size && !m_packed_elements[index].is_empty();
|
return inline_has_index(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<ValueAndAttributes> SimpleIndexedPropertyStorage::get(u32 index) const
|
Optional<ValueAndAttributes> SimpleIndexedPropertyStorage::get(u32 index) const
|
||||||
{
|
{
|
||||||
if (!has_index(index))
|
return inline_get(index);
|
||||||
return {};
|
|
||||||
return ValueAndAttributes { m_packed_elements[index], default_attributes };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleIndexedPropertyStorage::grow_storage_if_needed()
|
void SimpleIndexedPropertyStorage::grow_storage_if_needed()
|
||||||
|
|
|
@ -74,6 +74,18 @@ public:
|
||||||
|
|
||||||
Vector<Value> const& elements() const { return m_packed_elements; }
|
Vector<Value> const& elements() const { return m_packed_elements; }
|
||||||
|
|
||||||
|
[[nodiscard]] bool inline_has_index(u32 index) const
|
||||||
|
{
|
||||||
|
return index < m_array_size && !m_packed_elements.data()[index].is_empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Optional<ValueAndAttributes> inline_get(u32 index) const
|
||||||
|
{
|
||||||
|
if (!inline_has_index(index))
|
||||||
|
return {};
|
||||||
|
return ValueAndAttributes { m_packed_elements.data()[index], default_attributes };
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend GenericIndexedPropertyStorage;
|
friend GenericIndexedPropertyStorage;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue