From 8bdf6441b182674c0803750313888daf17f0220c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 31 Jan 2022 15:55:54 +0100 Subject: [PATCH] LibJS: Use u32 for the JS::Shape property count We don't need to support more than 2^32 object properties anyway, so there's no point in using 64-bit property counts. This small reduction in memory usage makes test-js run ~10% faster on x86_64 locally. --- Userland/Libraries/LibJS/Runtime/Shape.cpp | 13 ++++++------- Userland/Libraries/LibJS/Runtime/Shape.h | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Shape.cpp b/Userland/Libraries/LibJS/Runtime/Shape.cpp index e07cfd01fa9..0b0f2f96b7b 100644 --- a/Userland/Libraries/LibJS/Runtime/Shape.cpp +++ b/Userland/Libraries/LibJS/Runtime/Shape.cpp @@ -150,11 +150,6 @@ FLATTEN HashMap const& Shape::property_table() return *m_property_table; } -size_t Shape::property_count() const -{ - return m_property_count; -} - Vector Shape::property_table_ordered() const { auto vec = Vector(); @@ -207,7 +202,9 @@ void Shape::add_property_to_unique_shape(const StringOrSymbol& property_name, Pr VERIFY(is_unique()); VERIFY(m_property_table); VERIFY(!m_property_table->contains(property_name)); - m_property_table->set(property_name, { m_property_table->size(), attributes }); + m_property_table->set(property_name, { static_cast(m_property_table->size()), attributes }); + + VERIFY(m_property_count < NumericLimits::max()); ++m_property_count; } @@ -238,8 +235,10 @@ void Shape::add_property_without_transition(StringOrSymbol const& property_name, { VERIFY(property_name.is_valid()); ensure_property_table(); - if (m_property_table->set(property_name, { m_property_count, attributes }) == AK::HashSetResult::InsertedNewEntry) + if (m_property_table->set(property_name, { m_property_count, attributes }) == AK::HashSetResult::InsertedNewEntry) { + VERIFY(m_property_count < NumericLimits::max()); ++m_property_count; + } } FLATTEN void Shape::add_property_without_transition(PropertyKey const& property_name, PropertyAttributes attributes) diff --git a/Userland/Libraries/LibJS/Runtime/Shape.h b/Userland/Libraries/LibJS/Runtime/Shape.h index 55247bed2d3..b2712880c56 100644 --- a/Userland/Libraries/LibJS/Runtime/Shape.h +++ b/Userland/Libraries/LibJS/Runtime/Shape.h @@ -19,7 +19,7 @@ namespace JS { struct PropertyMetadata { - size_t offset { 0 }; + u32 offset { 0 }; PropertyAttributes attributes { 0 }; }; @@ -70,7 +70,7 @@ public: Optional lookup(const StringOrSymbol&) const; const HashMap& property_table() const; - size_t property_count() const; + u32 property_count() const { return m_property_count; } struct Property { StringOrSymbol key; @@ -107,7 +107,7 @@ private: Shape* m_previous { nullptr }; StringOrSymbol m_property_name; Object* m_prototype { nullptr }; - size_t m_property_count { 0 }; + u32 m_property_count { 0 }; PropertyAttributes m_attributes { 0 }; TransitionType m_transition_type : 6 { TransitionType::Invalid };