1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

LibJS: Add a number-indexed property storage to all Objects

Objects can have both named and indexed properties. Previously we kept
all property names as strings. This patch separates named and indexed
properties and splits them between Object::m_storage and m_elements.

This allows us to do much faster array-style access using numeric
indices. It also makes the Array class much less special, since all
Objects now have number-indexed storage. :^)
This commit is contained in:
Andreas Kling 2020-04-06 16:53:02 +02:00
parent 65dd9d5ad3
commit 90ba0145f6
6 changed files with 69 additions and 50 deletions

View file

@ -35,9 +35,7 @@ public:
Array();
virtual ~Array() override;
i32 length() const { return static_cast<i32>(m_elements.size()); }
const Vector<Value>& elements() const { return m_elements; }
Vector<Value>& elements() { return m_elements; }
i32 length() const { return static_cast<i32>(elements().size()); }
Value shift();
Value pop();
@ -45,15 +43,10 @@ public:
private:
virtual const char* class_name() const override { return "Array"; }
virtual void visit_children(Cell::Visitor&) override;
virtual bool is_array() const override { return true; }
virtual Optional<Value> get_own_property(const Object& this_object, const FlyString& property_name) const override;
virtual bool put_own_property(Object& this_object, const FlyString& property_name, Value) override;
static Value length_getter(Interpreter&);
static void length_setter(Interpreter&, Value);
Vector<Value> m_elements;
};
}