mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
Replace the OwnPtr<IndexedPropertyStorage> indirection with inline indexed element storage directly on Object. This eliminates virtual dispatch and reduces indirection for indexed property access. The new system uses three storage kinds tracked by IndexedStorageKind: - Packed: Dense array, no holes. Elements stored in a malloced Value* array with capacity header (same layout as named properties). - Holey: Dense array with possible holes marked by empty sentinel. Same physical layout as Packed. - Dictionary: Sparse storage using GenericIndexedPropertyStorage, type-punned into the m_indexed_elements pointer. Transitions: None->Packed->Holey->Dictionary (mostly monotonic). Dictionary mode triggers on non-default attributes or sparse arrays. Object keeps the same 48-byte size since m_indexed_elements (8 bytes) replaces IndexedProperties (8 bytes), and the storage kind + array size fit in existing padding alongside m_flags. The asm interpreter benefits from one fewer indirection: it now reads the element pointer and array size directly from Object fields instead of chasing through OwnPtr -> IndexedPropertyStorage -> Vector. Removes: IndexedProperties, SimpleIndexedPropertyStorage, IndexedPropertyStorage, IndexedPropertyIterator. Keeps: GenericIndexedPropertyStorage (for Dictionary mode).
60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <LibJS/Export.h>
|
|
#include <LibJS/Runtime/Shape.h>
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
namespace JS {
|
|
|
|
struct ValueAndAttributes {
|
|
Value value;
|
|
PropertyAttributes attributes { default_attributes };
|
|
|
|
Optional<u32> property_offset {};
|
|
|
|
void visit_edges(Cell::Visitor& visitor)
|
|
{
|
|
visitor.visit(value);
|
|
}
|
|
};
|
|
|
|
class GenericIndexedPropertyStorage {
|
|
public:
|
|
explicit GenericIndexedPropertyStorage()
|
|
{
|
|
}
|
|
|
|
bool has_index(u32 index) const;
|
|
Optional<ValueAndAttributes> get(u32 index) const;
|
|
void put(u32 index, Value value, PropertyAttributes attributes = default_attributes);
|
|
void remove(u32 index);
|
|
|
|
ValueAndAttributes take_first();
|
|
ValueAndAttributes take_last();
|
|
|
|
size_t size() const { return m_sparse_elements.size(); }
|
|
size_t array_like_size() const { return m_array_size; }
|
|
bool set_array_like_size(size_t new_size);
|
|
|
|
void visit_edges(Cell::Visitor& visitor)
|
|
{
|
|
for (auto& element : m_sparse_elements)
|
|
element.value.visit_edges(visitor);
|
|
}
|
|
|
|
HashMap<u32, ValueAndAttributes> const& sparse_elements() const { return m_sparse_elements; }
|
|
|
|
private:
|
|
size_t m_array_size { 0 };
|
|
HashMap<u32, ValueAndAttributes> m_sparse_elements;
|
|
};
|
|
|
|
}
|