LibJS: Make use of existing property tables when reifying new ones

When reifying a shape transition chain, look for the nearest previous
shape in the transition chain that has a property table already, and
use that as the starting point.

This achieves two things:

1. We do less work when reifying property tables that already have
   partial property tables earlier in the chain.

2. This enables adding properties to a shape without performing a
   transition. This will be useful for initializing runtime objects
   with way fewer allocations. See next patch. :^)
This commit is contained in:
Andreas Kling 2020-10-05 18:16:22 +02:00
parent 52c31bb743
commit 50ab87f651
Notes: sideshowbarker 2024-07-19 02:01:56 +09:00

View file

@ -148,16 +148,22 @@ void Shape::ensure_property_table() const
if (m_property_table)
return;
m_property_table = make<HashMap<StringOrSymbol, PropertyMetadata>>();
m_property_table->ensure_capacity(m_property_count);
DeferGC defer(heap());
u32 next_offset = 0;
Vector<const Shape*, 64> transition_chain;
for (auto* shape = this; shape->m_previous; shape = shape->m_previous) {
for (auto* shape = m_previous; shape; shape = shape->m_previous) {
if (shape->m_property_table) {
*m_property_table = *shape->m_property_table;
next_offset = shape->m_property_count;
break;
}
transition_chain.append(shape);
}
transition_chain.append(this);
u32 next_offset = 0;
for (ssize_t i = transition_chain.size() - 1; i >= 0; --i) {
auto* shape = transition_chain[i];
if (!shape->m_property_name.is_valid()) {