mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:17:34 +00:00
LibWeb: Make LayoutState use HashMap instead of potentially huge Vector
Before this change, LayoutState essentially had a Vector<UsedValues*> resized to the exact number of layout nodes in the current document. When a nested layout is performed (to calculate the intrinsic size of something), we make a new LayoutState with its own Vector. If an entry is missing in a nested LayoutState, we check the parent chain all the way up to the root. Because each nested LayoutState had to allocate a new Vector with space for all layout nodes, this could get really nasty on very large pages (such as the ECMA262 specification). This patch replaces the Vector with a HashMap. There's now a small cost to lookups, but what we get in return is the ability to handle huge layout trees without spending eternity in page faults.
This commit is contained in:
parent
e83681ee34
commit
e2c72922f6
6 changed files with 35 additions and 42 deletions
|
@ -29,12 +29,8 @@ struct LayoutState {
|
|||
{
|
||||
}
|
||||
|
||||
explicit LayoutState(LayoutState const* parent)
|
||||
: m_parent(parent)
|
||||
, m_root(find_root())
|
||||
{
|
||||
used_values_per_layout_node.resize(m_root.used_values_per_layout_node.size());
|
||||
}
|
||||
explicit LayoutState(LayoutState const* parent);
|
||||
~LayoutState();
|
||||
|
||||
LayoutState const& find_root() const
|
||||
{
|
||||
|
@ -153,7 +149,7 @@ struct LayoutState {
|
|||
// NOTE: get() will not CoW the UsedValues.
|
||||
UsedValues const& get(NodeWithStyleAndBoxModelMetrics const&) const;
|
||||
|
||||
Vector<OwnPtr<UsedValues>> used_values_per_layout_node;
|
||||
HashMap<Layout::Node const*, NonnullOwnPtr<UsedValues>> used_values_per_layout_node;
|
||||
|
||||
// We cache intrinsic sizes once determined, as they will not change over the course of a full layout.
|
||||
// This avoids computing them several times while performing flex layout.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue