From ee4948b9e797766833f25f5924853d4f71b0c65b Mon Sep 17 00:00:00 2001 From: iliadsh Date: Thu, 9 Nov 2023 07:32:48 +0000 Subject: [PATCH] LibJS: Devirtualize is_simple_storage() --- .../LibJS/Runtime/IndexedProperties.cpp | 4 +++- .../LibJS/Runtime/IndexedProperties.h | 21 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp b/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp index e0245cb3f0..0fb196f5b8 100644 --- a/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp +++ b/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp @@ -14,7 +14,8 @@ constexpr const size_t SPARSE_ARRAY_HOLE_THRESHOLD = 200; constexpr const size_t LENGTH_SETTER_GENERIC_STORAGE_THRESHOLD = 4 * MiB; SimpleIndexedPropertyStorage::SimpleIndexedPropertyStorage(Vector&& initial_values) - : m_array_size(initial_values.size()) + : IndexedPropertyStorage(IsSimpleStorage::Yes) + , m_array_size(initial_values.size()) , m_packed_elements(move(initial_values)) { } @@ -83,6 +84,7 @@ bool SimpleIndexedPropertyStorage::set_array_like_size(size_t new_size) } GenericIndexedPropertyStorage::GenericIndexedPropertyStorage(SimpleIndexedPropertyStorage&& storage) + : IndexedPropertyStorage(IsSimpleStorage::No) { m_array_size = storage.array_like_size(); for (size_t i = 0; i < storage.m_packed_elements.size(); ++i) { diff --git a/Userland/Libraries/LibJS/Runtime/IndexedProperties.h b/Userland/Libraries/LibJS/Runtime/IndexedProperties.h index a6bd758fab..cc895c4d69 100644 --- a/Userland/Libraries/LibJS/Runtime/IndexedProperties.h +++ b/Userland/Libraries/LibJS/Runtime/IndexedProperties.h @@ -27,6 +27,11 @@ class IndexedPropertyStorage { public: virtual ~IndexedPropertyStorage() = default; + enum class IsSimpleStorage { + No, + Yes, + }; + virtual bool has_index(u32 index) const = 0; virtual Optional get(u32 index) const = 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 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 { public: - SimpleIndexedPropertyStorage() = default; + SimpleIndexedPropertyStorage() + : IndexedPropertyStorage(IsSimpleStorage::Yes) {}; explicit SimpleIndexedPropertyStorage(Vector&& initial_values); 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 bool set_array_like_size(size_t new_size) override; - virtual bool is_simple_storage() const override { return true; } Vector const& elements() const { return m_packed_elements; } private: @@ -74,7 +86,8 @@ private: class GenericIndexedPropertyStorage final : public IndexedPropertyStorage { public: explicit GenericIndexedPropertyStorage(SimpleIndexedPropertyStorage&&); - explicit GenericIndexedPropertyStorage() = default; + explicit GenericIndexedPropertyStorage() + : IndexedPropertyStorage(IsSimpleStorage::No) {}; virtual bool has_index(u32 index) const override; virtual Optional get(u32 index) const override;