mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:07:45 +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
|
@ -859,13 +859,11 @@ void Document::update_layout()
|
|||
auto viewport_rect = browsing_context()->viewport_rect();
|
||||
|
||||
if (!m_layout_root) {
|
||||
m_next_layout_node_serial_id = 0;
|
||||
Layout::TreeBuilder tree_builder;
|
||||
m_layout_root = verify_cast<Layout::Viewport>(*tree_builder.build(*this));
|
||||
}
|
||||
|
||||
Layout::LayoutState layout_state;
|
||||
layout_state.used_values_per_layout_node.resize(layout_node_count());
|
||||
|
||||
{
|
||||
Layout::BlockFormattingContext root_formatting_context(layout_state, *m_layout_root, nullptr);
|
||||
|
|
|
@ -97,9 +97,6 @@ public:
|
|||
|
||||
JS::GCPtr<Selection::Selection> get_selection() const;
|
||||
|
||||
size_t next_layout_node_serial_id(Badge<Layout::Node>) { return m_next_layout_node_serial_id++; }
|
||||
size_t layout_node_count() const { return m_next_layout_node_serial_id; }
|
||||
|
||||
DeprecatedString cookie(Cookie::Source = Cookie::Source::NonHttp);
|
||||
void set_cookie(DeprecatedString const&, Cookie::Source = Cookie::Source::NonHttp);
|
||||
|
||||
|
@ -493,8 +490,6 @@ private:
|
|||
|
||||
WebIDL::ExceptionOr<void> run_the_document_write_steps(DeprecatedString);
|
||||
|
||||
size_t m_next_layout_node_serial_id { 0 };
|
||||
|
||||
OwnPtr<CSS::StyleComputer> m_style_computer;
|
||||
JS::GCPtr<CSS::StyleSheetList> m_style_sheets;
|
||||
JS::GCPtr<Node> m_hovered_node;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue