mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:57:36 +00:00
LibJS: Make marking object indexed properties less allocation-heavy
We were building up a vector with all the values in an object's indexed property storage, and then iterating over the vector to mark values. Instead of this, simply iterate over the property storage directly. :^)
This commit is contained in:
parent
930fae633e
commit
6c4b823cef
2 changed files with 17 additions and 2 deletions
|
@ -169,6 +169,20 @@ public:
|
||||||
|
|
||||||
Vector<ValueAndAttributes> values_unordered() const;
|
Vector<ValueAndAttributes> values_unordered() const;
|
||||||
|
|
||||||
|
template<typename Callback>
|
||||||
|
void for_each_value(Callback callback)
|
||||||
|
{
|
||||||
|
if (m_storage->is_simple_storage()) {
|
||||||
|
for (auto& value : static_cast<SimpleIndexedPropertyStorage&>(*m_storage).elements())
|
||||||
|
callback(value);
|
||||||
|
} else {
|
||||||
|
for (auto& element : static_cast<const GenericIndexedPropertyStorage&>(*m_storage).packed_elements())
|
||||||
|
callback(element.value);
|
||||||
|
for (auto& element : static_cast<const GenericIndexedPropertyStorage&>(*m_storage).sparse_elements())
|
||||||
|
callback(element.value.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void switch_to_generic_storage();
|
void switch_to_generic_storage();
|
||||||
|
|
||||||
|
|
|
@ -818,8 +818,9 @@ void Object::visit_edges(Cell::Visitor& visitor)
|
||||||
for (auto& value : m_storage)
|
for (auto& value : m_storage)
|
||||||
visitor.visit(value);
|
visitor.visit(value);
|
||||||
|
|
||||||
for (auto& value : m_indexed_properties.values_unordered())
|
m_indexed_properties.for_each_value([&visitor](auto& value) {
|
||||||
visitor.visit(value.value);
|
visitor.visit(value);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Object::has_property(const PropertyName& property_name) const
|
bool Object::has_property(const PropertyName& property_name) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue