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.
This commit is contained in:
Andreas Kling 2022-01-31 15:55:54 +01:00
parent 7a742b17da
commit 8bdf6441b1
Notes: sideshowbarker 2024-07-17 19:55:47 +09:00
2 changed files with 9 additions and 10 deletions

View file

@ -150,11 +150,6 @@ FLATTEN HashMap<StringOrSymbol, PropertyMetadata> const& Shape::property_table()
return *m_property_table;
}
size_t Shape::property_count() const
{
return m_property_count;
}
Vector<Shape::Property> Shape::property_table_ordered() const
{
auto vec = Vector<Shape::Property>();
@ -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<u32>(m_property_table->size()), attributes });
VERIFY(m_property_count < NumericLimits<u32>::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<u32>::max());
++m_property_count;
}
}
FLATTEN void Shape::add_property_without_transition(PropertyKey const& property_name, PropertyAttributes attributes)

View file

@ -19,7 +19,7 @@
namespace JS {
struct PropertyMetadata {
size_t offset { 0 };
u32 offset { 0 };
PropertyAttributes attributes { 0 };
};
@ -70,7 +70,7 @@ public:
Optional<PropertyMetadata> lookup(const StringOrSymbol&) const;
const HashMap<StringOrSymbol, PropertyMetadata>& 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 };