mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +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:
parent
65dd9d5ad3
commit
90ba0145f6
6 changed files with 69 additions and 50 deletions
|
@ -43,7 +43,10 @@ public:
|
|||
Shape& shape() { return *m_shape; }
|
||||
const Shape& shape() const { return *m_shape; }
|
||||
|
||||
Optional<Value> get_by_index(i32 property_index) const;
|
||||
Optional<Value> get(const FlyString& property_name) const;
|
||||
|
||||
void put_by_index(i32 property_index, Value);
|
||||
void put(const FlyString& property_name, Value);
|
||||
|
||||
virtual Optional<Value> get_own_property(const Object& this_object, const FlyString& property_name) const;
|
||||
|
@ -81,11 +84,15 @@ public:
|
|||
|
||||
Value get_direct(size_t index) const { return m_storage[index]; }
|
||||
|
||||
const Vector<Value>& elements() const { return m_elements; }
|
||||
Vector<Value>& elements() { return m_elements; }
|
||||
|
||||
private:
|
||||
void set_shape(Shape&);
|
||||
|
||||
Shape* m_shape { nullptr };
|
||||
Vector<Value> m_storage;
|
||||
Vector<Value> m_elements;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue