Changeset 254634 in webkit
- Timestamp:
- Jan 15, 2020 1:49:37 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r254631 r254634 1 2020-01-15 Antti Koivisto <antti@apple.com> 2 3 [LFC] Cache display box for the first LayoutState to Layout::Box 4 https://bugs.webkit.org/show_bug.cgi?id=206288 5 6 Reviewed by Zalan Bujtas. 7 8 Add a single item cache for the common case to avoid using the hash. 9 10 * layout/FormattingState.cpp: 11 (WebCore::Layout::FormattingState::displayBox): 12 * layout/LayoutState.cpp: 13 (WebCore::Layout::LayoutState::displayBoxForRootLayoutBox): 14 (WebCore::Layout::LayoutState::ensureDisplayBoxForLayoutBoxSlow): 15 (WebCore::Layout::LayoutState::displayBoxForLayoutBox): Deleted. 16 (WebCore::Layout::LayoutState::displayBoxForLayoutBox const): Deleted. 17 * layout/LayoutState.h: 18 (WebCore::Layout::Box::cachedDisplayBoxForLayoutState const): 19 (WebCore::Layout::LayoutState::hasDisplayBox const): 20 (WebCore::Layout::LayoutState::ensureDisplayBoxForLayoutBox): 21 (WebCore::Layout::LayoutState::displayBoxForLayoutBox const): 22 * layout/layouttree/LayoutBox.cpp: 23 (WebCore::Layout::Box::setCachedDisplayBoxForLayoutState const): 24 * layout/layouttree/LayoutBox.h: 25 (WebCore::Layout::Box::hasCachedDisplayBox const): 26 * layout/layouttree/LayoutTreeBuilder.h: 27 1 28 2020-01-15 Simon Fraser <simon.fraser@apple.com> 2 29 -
trunk/Source/WebCore/layout/FormattingState.cpp
r250064 r254634 52 52 // Should never need to mutate a display box outside of the formatting context. 53 53 ASSERT(&layoutState().establishedFormattingState(layoutBox.formattingContextRoot()) == this); 54 return layoutState(). displayBoxForLayoutBox(layoutBox);54 return layoutState().ensureDisplayBoxForLayoutBox(layoutBox); 55 55 } 56 56 -
trunk/Source/WebCore/layout/LayoutState.cpp
r253985 r254634 61 61 Display::Box& LayoutState::displayBoxForRootLayoutBox() 62 62 { 63 return displayBoxForLayoutBox(m_layoutTreeContent->rootLayoutBox());63 return ensureDisplayBoxForLayoutBox(m_layoutTreeContent->rootLayoutBox()); 64 64 } 65 65 66 Display::Box& LayoutState:: displayBoxForLayoutBox(const Box& layoutBox)66 Display::Box& LayoutState::ensureDisplayBoxForLayoutBoxSlow(const Box& layoutBox) 67 67 { 68 if (layoutBox.canCacheForLayoutState(*this)) { 69 ASSERT(!layoutBox.cachedDisplayBoxForLayoutState(*this)); 70 auto newBox = makeUnique<Display::Box>(); 71 auto& newBoxPtr = *newBox; 72 layoutBox.setCachedDisplayBoxForLayoutState(*this, WTFMove(newBox)); 73 return newBoxPtr; 74 } 75 68 76 return *m_layoutToDisplayBox.ensure(&layoutBox, [] { 69 77 return makeUnique<Display::Box>(); 70 78 }).iterator->value; 71 }72 73 const Display::Box& LayoutState::displayBoxForLayoutBox(const Box& layoutBox) const74 {75 ASSERT(hasDisplayBox(layoutBox));76 return *m_layoutToDisplayBox.get(&layoutBox);77 79 } 78 80 -
trunk/Source/WebCore/layout/LayoutState.h
r253985 r254634 43 43 namespace Layout { 44 44 45 class Box;46 45 class FormattingContext; 47 46 class FormattingState; 48 47 49 class LayoutState {48 class LayoutState : public CanMakeWeakPtr<LayoutState> { 50 49 WTF_MAKE_ISO_ALLOCATED(LayoutState); 51 50 public: … … 64 63 65 64 Display::Box& displayBoxForRootLayoutBox(); 66 Display::Box& displayBoxForLayoutBox(const Box& layoutBox); 67 const Display::Box& displayBoxForLayoutBox(const Box& layoutBox) const; 68 bool hasDisplayBox(const Box& layoutBox) const { return m_layoutToDisplayBox.contains(&layoutBox); } 65 Display::Box& ensureDisplayBoxForLayoutBox(const Box&); 66 const Display::Box& displayBoxForLayoutBox(const Box&) const; 67 68 bool hasDisplayBox(const Box&) const; 69 69 70 70 enum class QuirksMode { No, Limited, Yes }; … … 85 85 private: 86 86 void setQuirksMode(QuirksMode quirksMode) { m_quirksMode = quirksMode; } 87 Display::Box& ensureDisplayBoxForLayoutBoxSlow(const Box&); 87 88 88 89 HashMap<const Container*, std::unique_ptr<FormattingState>> m_formattingStates; … … 98 99 }; 99 100 101 inline bool LayoutState::hasDisplayBox(const Box& layoutBox) const 102 { 103 if (layoutBox.cachedDisplayBoxForLayoutState(*this)) 104 return true; 105 return m_layoutToDisplayBox.contains(&layoutBox); 106 } 107 108 inline Display::Box& LayoutState::ensureDisplayBoxForLayoutBox(const Box& layoutBox) 109 { 110 if (auto* displayBox = layoutBox.cachedDisplayBoxForLayoutState(*this)) 111 return *displayBox; 112 return ensureDisplayBoxForLayoutBoxSlow(layoutBox); 113 } 114 115 inline const Display::Box& LayoutState::displayBoxForLayoutBox(const Box& layoutBox) const 116 { 117 if (auto* displayBox = layoutBox.cachedDisplayBoxForLayoutState(*this)) 118 return *displayBox; 119 ASSERT(m_layoutToDisplayBox.contains(&layoutBox)); 120 return *m_layoutToDisplayBox.get(&layoutBox); 121 } 122 100 123 #ifndef NDEBUG 101 124 inline void LayoutState::registerFormattingContext(const FormattingContext& formattingContext) … … 107 130 #endif 108 131 132 // These Layout::Box function are here to allow inlining. 133 inline bool Box::canCacheForLayoutState(const LayoutState& layoutState) const 134 { 135 return !m_cachedLayoutState || m_cachedLayoutState.get() == &layoutState; 136 } 137 138 inline Display::Box* Box::cachedDisplayBoxForLayoutState(const LayoutState& layoutState) const 139 { 140 if (m_cachedLayoutState.get() != &layoutState) 141 return nullptr; 142 return m_cachedDisplayBoxForLayoutState.get(); 143 } 144 109 145 } 110 146 } -
trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp
r254410 r254634 31 31 #include "LayoutContainer.h" 32 32 #include "LayoutPhase.h" 33 #include "LayoutState.h" 33 34 #include "RenderStyle.h" 34 35 #include <wtf/IsoMallocInlines.h> … … 445 446 } 446 447 448 void Box::setCachedDisplayBoxForLayoutState(LayoutState& layoutState, std::unique_ptr<Display::Box> box) const 449 { 450 ASSERT(!m_cachedLayoutState); 451 m_cachedLayoutState = makeWeakPtr(layoutState); 452 m_cachedDisplayBoxForLayoutState = WTFMove(box); 453 } 454 447 455 Box::RareDataMap& Box::rareDataMap() 448 456 { -
trunk/Source/WebCore/layout/layouttree/LayoutBox.h
r254410 r254634 35 35 36 36 namespace WebCore { 37 38 namespace Display { 39 class Box; 40 } 41 37 42 namespace Layout { 38 43 39 44 class Container; 45 class LayoutState; 40 46 class TreeBuilder; 41 47 … … 168 174 void setIsAnonymous() { m_isAnonymous = true; } 169 175 176 bool canCacheForLayoutState(const LayoutState&) const; 177 Display::Box* cachedDisplayBoxForLayoutState(const LayoutState&) const; 178 void setCachedDisplayBoxForLayoutState(LayoutState&, std::unique_ptr<Display::Box>) const; 179 170 180 protected: 171 181 Box(Optional<ElementAttributes>, Optional<TextContext>, RenderStyle&&, BaseTypeFlags); … … 202 212 const Optional<TextContext> m_textContext; 203 213 214 // First LayoutState gets a direct cache. 215 mutable WeakPtr<LayoutState> m_cachedLayoutState; 216 mutable std::unique_ptr<Display::Box> m_cachedDisplayBoxForLayoutState; 217 204 218 unsigned m_baseTypeFlags : 6; 205 219 bool m_hasRareData : 1; -
trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h
r253921 r254634 28 28 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 29 29 30 #include "LayoutBox.h"31 30 #include <wtf/IsoMalloc.h> 32 31 #include <wtf/WeakPtr.h>
Note: See TracChangeset
for help on using the changeset viewer.