[LFC] Construct the Display::Box objects on demand.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Sep 2018 22:08:23 +0000 (22:08 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Sep 2018 22:08:23 +0000 (22:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189320

Reviewed by Antti Koivisto.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::initializeRoot):
(WebCore::Layout::LayoutContext::displayBoxForLayoutBox const):
(WebCore::Layout::LayoutContext::createDisplayBox): Deleted.
* layout/LayoutContext.h:
(WebCore::Layout::LayoutContext::displayBoxForLayoutBox const): Deleted.
* layout/Verification.cpp:
(WebCore::Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree const):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::layout const):
* layout/displaytree/DisplayBox.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235711 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContext.cpp
Source/WebCore/layout/LayoutContext.cpp
Source/WebCore/layout/LayoutContext.h
Source/WebCore/layout/Verification.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/displaytree/DisplayBox.h

index 3b5844f..1b4b8e7 100644 (file)
@@ -1,3 +1,24 @@
+2018-09-05  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Construct the Display::Box objects on demand.
+        https://bugs.webkit.org/show_bug.cgi?id=189320
+
+        Reviewed by Antti Koivisto.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::initializeRoot):
+        (WebCore::Layout::LayoutContext::displayBoxForLayoutBox const):
+        (WebCore::Layout::LayoutContext::createDisplayBox): Deleted.
+        * layout/LayoutContext.h:
+        (WebCore::Layout::LayoutContext::displayBoxForLayoutBox const): Deleted.
+        * layout/Verification.cpp:
+        (WebCore::Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree const):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::layout const):
+        * layout/displaytree/DisplayBox.h:
+
 2018-09-05  Woodrow Wang  <woodrow_wang@apple.com>
 
         Add infrastructure to dump resource load statistics
index 91b0d1d..1ab6f71 100644 (file)
@@ -113,7 +113,6 @@ void FormattingContext::layoutOutOfFlowDescendants(LayoutContext& layoutContext,
 
     for (auto& outOfFlowBox : container.outOfFlowDescendants()) {
         auto& layoutBox = *outOfFlowBox;
-        layoutContext.createDisplayBox(layoutBox);
 
         ASSERT(layoutBox.establishesFormattingContext());
         auto formattingContext = layoutContext.formattingContext(layoutBox);
index 552a779..07398c9 100644 (file)
@@ -54,7 +54,7 @@ void LayoutContext::initializeRoot(const Container& root, const LayoutSize& cont
     ASSERT(root.establishesFormattingContext());
 
     m_root = makeWeakPtr(const_cast<Container&>(root));
-    auto& displayBox = createDisplayBox(root);
+    auto& displayBox = displayBoxForLayoutBox(root);
 
     // FIXME: m_root could very well be a formatting context root with ancestors and resolvable border and padding (as opposed to the topmost root)
     displayBox.setHorizontalMargin({ });
@@ -86,12 +86,11 @@ void LayoutContext::layoutFormattingContextSubtree(const Box& layoutRoot)
     formattingContext->layoutOutOfFlowDescendants(*this, layoutRoot);
 }
 
-Display::Box& LayoutContext::createDisplayBox(const Box& layoutBox)
+Display::Box& LayoutContext::displayBoxForLayoutBox(const Box& layoutBox) const
 {
-    std::unique_ptr<Display::Box> displayBox(new Display::Box(layoutBox.style()));
-    auto* displayBoxPtr = displayBox.get();
-    m_layoutToDisplayBox.add(&layoutBox, WTFMove(displayBox));
-    return *displayBoxPtr;
+    return *m_layoutToDisplayBox.ensure(&layoutBox, [&layoutBox] {
+        return std::make_unique<Display::Box>(layoutBox.style());
+    }).iterator->value;
 }
 
 void LayoutContext::styleChanged(const Box& layoutBox, StyleDiff styleDiff)
index cc05b91..37b77b4 100644 (file)
@@ -80,8 +80,7 @@ public:
     FormattingState& formattingStateForBox(const Box&) const;
     FormattingState& establishedFormattingState(const Box& formattingRoot);
 
-    Display::Box& createDisplayBox(const Box&);
-    Display::Box& displayBoxForLayoutBox(const Box& layoutBox) const { return *m_layoutToDisplayBox.get(&layoutBox); }
+    Display::Box& displayBoxForLayoutBox(const Box& layoutBox) const;
 
     bool inQuirksMode() const { return m_inQuirksMode; }
     // For testing purposes only
@@ -93,7 +92,7 @@ private:
     WeakPtr<Container> m_root;
     HashSet<const Container*> m_formattingContextRootListForLayout;
     HashMap<const Box*, std::unique_ptr<FormattingState>> m_formattingStates;
-    HashMap<const Box*, std::unique_ptr<Display::Box>> m_layoutToDisplayBox;
+    mutable HashMap<const Box*, std::unique_ptr<Display::Box>> m_layoutToDisplayBox;
     bool m_inQuirksMode { false };
 };
 
index e8bc435..5cbc8cf 100644 (file)
@@ -219,6 +219,7 @@ void LayoutContext::verifyAndOutputMismatchingLayoutTree(const RenderView& rende
     showLayoutTree(*m_root.get(), this);
 #endif
     WTFLogAlways("%s", stream.release().utf8().data());
+    ASSERT_NOT_REACHED();
 }
 
 }
index a4c19de..bb1089c 100644 (file)
@@ -65,10 +65,8 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat
     FloatingContext floatingContext(formattingState.floatingState());
     // This is a post-order tree traversal layout.
     // The root container layout is done in the formatting context it lives in, not that one it creates, so let's start with the first child.
-    if (auto* firstChild = formattingRoot.firstInFlowOrFloatingChild()) {
+    if (auto* firstChild = formattingRoot.firstInFlowOrFloatingChild())
         layoutQueue.append(firstChild);
-        layoutContext.createDisplayBox(*firstChild);
-    }
     // 1. Go all the way down to the leaf node
     // 2. Compute static position and width as we traverse down
     // 3. As we climb back on the tree, compute height and finialize position
@@ -85,9 +83,7 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat
                 // Continue with next sibling if exists.
                 if (!layoutBox.nextInFlowOrFloatingSibling())
                     break;
-                auto* nextSibling = layoutBox.nextInFlowOrFloatingSibling();
-                layoutQueue.append(nextSibling);
-                layoutContext.createDisplayBox(*nextSibling);
+                layoutQueue.append(layoutBox.nextInFlowOrFloatingSibling());
                 continue;
             }
 
@@ -97,9 +93,7 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat
             computeWidthAndMargin(layoutContext, layoutBox);
             if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowOrFloatingChild())
                 break;
-            auto* firstChild = downcast<Container>(layoutBox).firstInFlowOrFloatingChild();
-            layoutQueue.append(firstChild);
-            layoutContext.createDisplayBox(*firstChild);
+            layoutQueue.append(downcast<Container>(layoutBox).firstInFlowOrFloatingChild());
         }
 
         // Climb back on the ancestors and compute height/final position.
@@ -121,7 +115,6 @@ void BlockFormattingContext::layout(LayoutContext& layoutContext, FormattingStat
             placeInFlowPositionedChildren(layoutContext, container);
             if (auto* nextSibling = container.nextInFlowOrFloatingSibling()) {
                 layoutQueue.append(nextSibling);
-                layoutContext.createDisplayBox(*nextSibling);
                 break;
             }
         }
index aef24e4..3630ee2 100644 (file)
@@ -56,6 +56,7 @@ public:
     friend class Layout::FloatingContext;
     friend class Layout::LayoutContext;
 
+    Box(const RenderStyle&);
     Box(const Box&);
 
     class Rect {
@@ -172,8 +173,6 @@ public:
     Rect contentBox() const;
 
 private:
-    Box(const RenderStyle&);
-
     struct Style {
         Style(const RenderStyle&);