mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
LibJS: Use OrderedHashMap for the Shape property table
This allows us to get rid of property_table_ordered() which was a heavy-handed way of iterating properties in insertion order by first copying them to a sorted Vector. Clients can now simply iterate property_table() directly. 3% speed-up on Kraken/ai-astar.js :^)
This commit is contained in:
parent
8ce9e51c97
commit
e33145aa4b
7 changed files with 13 additions and 27 deletions
|
@ -136,29 +136,17 @@ Optional<PropertyMetadata> Shape::lookup(StringOrSymbol const& property_key) con
|
|||
return property;
|
||||
}
|
||||
|
||||
FLATTEN HashMap<StringOrSymbol, PropertyMetadata> const& Shape::property_table() const
|
||||
FLATTEN OrderedHashMap<StringOrSymbol, PropertyMetadata> const& Shape::property_table() const
|
||||
{
|
||||
ensure_property_table();
|
||||
return *m_property_table;
|
||||
}
|
||||
|
||||
Vector<Shape::Property> Shape::property_table_ordered() const
|
||||
{
|
||||
auto vec = Vector<Shape::Property>();
|
||||
vec.resize(property_count());
|
||||
|
||||
for (auto& it : property_table()) {
|
||||
vec[it.value.offset] = { it.key, it.value };
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
void Shape::ensure_property_table() const
|
||||
{
|
||||
if (m_property_table)
|
||||
return;
|
||||
m_property_table = make<HashMap<StringOrSymbol, PropertyMetadata>>();
|
||||
m_property_table = make<OrderedHashMap<StringOrSymbol, PropertyMetadata>>();
|
||||
|
||||
u32 next_offset = 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue