summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-31 15:55:54 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-31 16:19:23 +0100
commit8bdf6441b182674c0803750313888daf17f0220c (patch)
tree9f8cca8cc336654a9669db87b090011f4785cb58 /Userland
parent7a742b17da1cc7e53ea272e733a5244c168afc10 (diff)
downloadserenity-8bdf6441b182674c0803750313888daf17f0220c.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Shape.cpp13
-rw-r--r--Userland/Libraries/LibJS/Runtime/Shape.h6
2 files changed, 9 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Shape.cpp b/Userland/Libraries/LibJS/Runtime/Shape.cpp
index e07cfd01fa..0b0f2f96b7 100644
--- a/Userland/Libraries/LibJS/Runtime/Shape.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Shape.cpp
@@ -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)
diff --git a/Userland/Libraries/LibJS/Runtime/Shape.h b/Userland/Libraries/LibJS/Runtime/Shape.h
index 55247bed2d..b2712880c5 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<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 };