From 50ab87f651728aa3488429a69c718f2380fdd678 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 5 Oct 2020 18:16:22 +0200 Subject: [PATCH] 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. :^) --- Libraries/LibJS/Runtime/Shape.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Libraries/LibJS/Runtime/Shape.cpp b/Libraries/LibJS/Runtime/Shape.cpp index 27cdba4654..49d0bfc816 100644 --- a/Libraries/LibJS/Runtime/Shape.cpp +++ b/Libraries/LibJS/Runtime/Shape.cpp @@ -148,16 +148,22 @@ void Shape::ensure_property_table() const if (m_property_table) return; m_property_table = make>(); - m_property_table->ensure_capacity(m_property_count); DeferGC defer(heap()); + u32 next_offset = 0; + Vector 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()) {