mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:58:12 +00:00
LibJS: Devirtualize is_simple_storage()
This commit is contained in:
parent
89da731aa6
commit
ee4948b9e7
2 changed files with 20 additions and 5 deletions
|
@ -14,7 +14,8 @@ constexpr const size_t SPARSE_ARRAY_HOLE_THRESHOLD = 200;
|
||||||
constexpr const size_t LENGTH_SETTER_GENERIC_STORAGE_THRESHOLD = 4 * MiB;
|
constexpr const size_t LENGTH_SETTER_GENERIC_STORAGE_THRESHOLD = 4 * MiB;
|
||||||
|
|
||||||
SimpleIndexedPropertyStorage::SimpleIndexedPropertyStorage(Vector<Value>&& initial_values)
|
SimpleIndexedPropertyStorage::SimpleIndexedPropertyStorage(Vector<Value>&& initial_values)
|
||||||
: m_array_size(initial_values.size())
|
: IndexedPropertyStorage(IsSimpleStorage::Yes)
|
||||||
|
, m_array_size(initial_values.size())
|
||||||
, m_packed_elements(move(initial_values))
|
, m_packed_elements(move(initial_values))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -83,6 +84,7 @@ bool SimpleIndexedPropertyStorage::set_array_like_size(size_t new_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericIndexedPropertyStorage::GenericIndexedPropertyStorage(SimpleIndexedPropertyStorage&& storage)
|
GenericIndexedPropertyStorage::GenericIndexedPropertyStorage(SimpleIndexedPropertyStorage&& storage)
|
||||||
|
: IndexedPropertyStorage(IsSimpleStorage::No)
|
||||||
{
|
{
|
||||||
m_array_size = storage.array_like_size();
|
m_array_size = storage.array_like_size();
|
||||||
for (size_t i = 0; i < storage.m_packed_elements.size(); ++i) {
|
for (size_t i = 0; i < storage.m_packed_elements.size(); ++i) {
|
||||||
|
|
|
@ -27,6 +27,11 @@ class IndexedPropertyStorage {
|
||||||
public:
|
public:
|
||||||
virtual ~IndexedPropertyStorage() = default;
|
virtual ~IndexedPropertyStorage() = default;
|
||||||
|
|
||||||
|
enum class IsSimpleStorage {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
};
|
||||||
|
|
||||||
virtual bool has_index(u32 index) const = 0;
|
virtual bool has_index(u32 index) const = 0;
|
||||||
virtual Optional<ValueAndAttributes> get(u32 index) const = 0;
|
virtual Optional<ValueAndAttributes> get(u32 index) const = 0;
|
||||||
virtual void put(u32 index, Value value, PropertyAttributes attributes = default_attributes) = 0;
|
virtual void put(u32 index, Value value, PropertyAttributes attributes = default_attributes) = 0;
|
||||||
|
@ -39,12 +44,20 @@ public:
|
||||||
virtual size_t array_like_size() const = 0;
|
virtual size_t array_like_size() const = 0;
|
||||||
virtual bool set_array_like_size(size_t new_size) = 0;
|
virtual bool set_array_like_size(size_t new_size) = 0;
|
||||||
|
|
||||||
virtual bool is_simple_storage() const { return false; }
|
bool is_simple_storage() const { return m_is_simple_storage; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit IndexedPropertyStorage(IsSimpleStorage is_simple_storage)
|
||||||
|
: m_is_simple_storage(is_simple_storage == IsSimpleStorage::Yes) {};
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_is_simple_storage { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class SimpleIndexedPropertyStorage final : public IndexedPropertyStorage {
|
class SimpleIndexedPropertyStorage final : public IndexedPropertyStorage {
|
||||||
public:
|
public:
|
||||||
SimpleIndexedPropertyStorage() = default;
|
SimpleIndexedPropertyStorage()
|
||||||
|
: IndexedPropertyStorage(IsSimpleStorage::Yes) {};
|
||||||
explicit SimpleIndexedPropertyStorage(Vector<Value>&& initial_values);
|
explicit SimpleIndexedPropertyStorage(Vector<Value>&& initial_values);
|
||||||
|
|
||||||
virtual bool has_index(u32 index) const override;
|
virtual bool has_index(u32 index) const override;
|
||||||
|
@ -59,7 +72,6 @@ public:
|
||||||
virtual size_t array_like_size() const override { return m_array_size; }
|
virtual size_t array_like_size() const override { return m_array_size; }
|
||||||
virtual bool set_array_like_size(size_t new_size) override;
|
virtual bool set_array_like_size(size_t new_size) override;
|
||||||
|
|
||||||
virtual bool is_simple_storage() const override { return true; }
|
|
||||||
Vector<Value> const& elements() const { return m_packed_elements; }
|
Vector<Value> const& elements() const { return m_packed_elements; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -74,7 +86,8 @@ private:
|
||||||
class GenericIndexedPropertyStorage final : public IndexedPropertyStorage {
|
class GenericIndexedPropertyStorage final : public IndexedPropertyStorage {
|
||||||
public:
|
public:
|
||||||
explicit GenericIndexedPropertyStorage(SimpleIndexedPropertyStorage&&);
|
explicit GenericIndexedPropertyStorage(SimpleIndexedPropertyStorage&&);
|
||||||
explicit GenericIndexedPropertyStorage() = default;
|
explicit GenericIndexedPropertyStorage()
|
||||||
|
: IndexedPropertyStorage(IsSimpleStorage::No) {};
|
||||||
|
|
||||||
virtual bool has_index(u32 index) const override;
|
virtual bool has_index(u32 index) const override;
|
||||||
virtual Optional<ValueAndAttributes> get(u32 index) const override;
|
virtual Optional<ValueAndAttributes> get(u32 index) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue