瀏覽代碼

LibWeb: Don't compute style *again* for elements in Layout::TreeBuilder

TreeBuilder wasn't taking advantage of the fact that we already have
computed style cached on each DOM::Element by the time we're
constructing a layout tree.

So instead of using the cached style, we recomputed it from scratch for
every element. This was done because invalidation was broken in many
places, but now that it's more or less trustworthy, stop recomputing
style on the fly in TreeBuilder and use what the preceding style update
pass gave us instead.

This basically cuts style computation work in half. :^)
Andreas Kling 3 年之前
父節點
當前提交
b8ee4dfda8
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp

+ 2 - 2
Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp

@@ -101,10 +101,10 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
     if (is<DOM::Element>(dom_node)) {
         auto& element = static_cast<DOM::Element&>(dom_node);
         element.clear_pseudo_element_nodes({});
-        style = style_computer.compute_style(element);
+        VERIFY(!element.needs_style_update());
+        style = element.computed_css_values();
         if (style->display().is_none())
             return;
-        element.set_computed_css_values(style);
         layout_node = element.create_layout_node(*style);
     } else if (is<DOM::Document>(dom_node)) {
         style = style_computer.create_document_style();