Title: [222953] trunk/Source/WebCore
Revision
222953
Author
[email protected]
Date
2017-10-05 19:41:35 -0700 (Thu, 05 Oct 2017)

Log Message

RenderTable should not hold section raw pointers
https://bugs.webkit.org/show_bug.cgi?id=177977
<rdar://problem/34846034>

Reviewed by Simon Fraser.

This enables us to remove forced recalcSections calls.

Covered by existing tests.

* rendering/RenderTable.cpp:
(WebCore::RenderTable::RenderTable):
(WebCore::resetSectionPointerIfNotBefore):
(WebCore::RenderTable::addChild):
(WebCore::RenderTable::recalcSections const):
(WebCore::RenderTable::sectionAbove const):
* rendering/RenderTable.h:
(WebCore::RenderTable::header const):
(WebCore::RenderTable::footer const):
(WebCore::RenderTable::firstBody const):
(WebCore::RenderTable::topSection const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (222952 => 222953)


--- trunk/Source/WebCore/ChangeLog	2017-10-06 02:36:20 UTC (rev 222952)
+++ trunk/Source/WebCore/ChangeLog	2017-10-06 02:41:35 UTC (rev 222953)
@@ -1,3 +1,27 @@
+2017-10-05  Zalan Bujtas  <[email protected]>
+
+        RenderTable should not hold section raw pointers
+        https://bugs.webkit.org/show_bug.cgi?id=177977
+        <rdar://problem/34846034>
+
+        Reviewed by Simon Fraser.
+
+        This enables us to remove forced recalcSections calls.
+
+        Covered by existing tests.
+
+        * rendering/RenderTable.cpp:
+        (WebCore::RenderTable::RenderTable):
+        (WebCore::resetSectionPointerIfNotBefore):
+        (WebCore::RenderTable::addChild):
+        (WebCore::RenderTable::recalcSections const):
+        (WebCore::RenderTable::sectionAbove const):
+        * rendering/RenderTable.h:
+        (WebCore::RenderTable::header const):
+        (WebCore::RenderTable::footer const):
+        (WebCore::RenderTable::firstBody const):
+        (WebCore::RenderTable::topSection const):
+
 2017-10-05  Dean Jackson  <[email protected]>
 
         Lots of missing frames in YouTube360 when fullscreen on MacBook

Modified: trunk/Source/WebCore/rendering/RenderTable.cpp (222952 => 222953)


--- trunk/Source/WebCore/rendering/RenderTable.cpp	2017-10-06 02:36:20 UTC (rev 222952)
+++ trunk/Source/WebCore/rendering/RenderTable.cpp	2017-10-06 02:41:35 UTC (rev 222953)
@@ -55,9 +55,6 @@
 
 RenderTable::RenderTable(Element& element, RenderStyle&& style)
     : RenderBlock(element, WTFMove(style), 0)
-    , m_head(nullptr)
-    , m_foot(nullptr)
-    , m_firstBody(nullptr)
     , m_currentBorder(nullptr)
     , m_collapsedBordersValid(false)
     , m_collapsedEmptyBorderIsPresent(false)
@@ -77,9 +74,6 @@
 
 RenderTable::RenderTable(Document& document, RenderStyle&& style)
     : RenderBlock(document, WTFMove(style), 0)
-    , m_head(nullptr)
-    , m_foot(nullptr)
-    , m_firstBody(nullptr)
     , m_currentBorder(nullptr)
     , m_collapsedBordersValid(false)
     , m_collapsedEmptyBorderIsPresent(false)
@@ -125,15 +119,15 @@
         invalidateCollapsedBorders();
 }
 
-static inline void resetSectionPointerIfNotBefore(RenderTableSection*& ptr, RenderObject* before)
+static inline void resetSectionPointerIfNotBefore(WeakPtr<RenderTableSection>& section, RenderObject* before)
 {
-    if (!before || !ptr)
+    if (!before || !section)
         return;
-    RenderObject* o = before->previousSibling();
-    while (o && o != ptr)
-        o = o->previousSibling();
-    if (!o)
-        ptr = 0;
+    auto* previousSibling = before->previousSibling();
+    while (previousSibling && previousSibling != section)
+        previousSibling = previousSibling->previousSibling();
+    if (!previousSibling)
+        section.clear();
 }
 
 void RenderTable::addChild(RenderPtr<RenderObject> child, RenderObject* beforeChild)
@@ -150,11 +144,11 @@
             case TABLE_HEADER_GROUP:
                 resetSectionPointerIfNotBefore(m_head, beforeChild);
                 if (!m_head) {
-                    m_head = downcast<RenderTableSection>(child.get());
+                    m_head = makeWeakPtr(downcast<RenderTableSection>(child.get()));
                 } else {
                     resetSectionPointerIfNotBefore(m_firstBody, beforeChild);
                     if (!m_firstBody) 
-                        m_firstBody = downcast<RenderTableSection>(child.get());
+                        m_firstBody = makeWeakPtr(downcast<RenderTableSection>(child.get()));
                 }
                 wrapInAnonymousSection = false;
                 break;
@@ -161,7 +155,7 @@
             case TABLE_FOOTER_GROUP:
                 resetSectionPointerIfNotBefore(m_foot, beforeChild);
                 if (!m_foot) {
-                    m_foot = downcast<RenderTableSection>(child.get());
+                    m_foot = makeWeakPtr(downcast<RenderTableSection>(child.get()));
                     wrapInAnonymousSection = false;
                     break;
                 }
@@ -169,7 +163,7 @@
             case TABLE_ROW_GROUP:
                 resetSectionPointerIfNotBefore(m_firstBody, beforeChild);
                 if (!m_firstBody)
-                    m_firstBody = downcast<RenderTableSection>(child.get());
+                    m_firstBody = makeWeakPtr(downcast<RenderTableSection>(child.get()));
                 wrapInAnonymousSection = false;
                 break;
             default:
@@ -1055,9 +1049,9 @@
 {
     ASSERT(m_needsSectionRecalc);
 
-    m_head = 0;
-    m_foot = 0;
-    m_firstBody = 0;
+    m_head.clear();
+    m_foot.clear();
+    m_firstBody.clear();
     m_hasColElements = false;
     m_hasCellColspanThatDeterminesTableWidth = hasCellColspanThatDeterminesTableWidth();
 
@@ -1074,9 +1068,9 @@
             if (is<RenderTableSection>(*child)) {
                 RenderTableSection& section = downcast<RenderTableSection>(*child);
                 if (!m_head)
-                    m_head = &section;
+                    m_head = makeWeakPtr(section);
                 else if (!m_firstBody)
-                    m_firstBody = &section;
+                    m_firstBody = makeWeakPtr(section);
                 section.recalcCellsIfNeeded();
             }
             break;
@@ -1084,9 +1078,9 @@
             if (is<RenderTableSection>(*child)) {
                 RenderTableSection& section = downcast<RenderTableSection>(*child);
                 if (!m_foot)
-                    m_foot = &section;
+                    m_foot = makeWeakPtr(section);
                 else if (!m_firstBody)
-                    m_firstBody = &section;
+                    m_firstBody = makeWeakPtr(section);
                 section.recalcCellsIfNeeded();
             }
             break;
@@ -1094,7 +1088,7 @@
             if (is<RenderTableSection>(*child)) {
                 RenderTableSection& section = downcast<RenderTableSection>(*child);
                 if (!m_firstBody)
-                    m_firstBody = &section;
+                    m_firstBody = makeWeakPtr(section);
                 section.recalcCellsIfNeeded();
             }
             break;
@@ -1363,7 +1357,7 @@
         prevSection = prevSection->previousSibling();
     }
     if (!prevSection && m_head && (skipEmptySections == DoNotSkipEmptySections || m_head->numRows()))
-        prevSection = m_head;
+        prevSection = m_head.get();
     return downcast<RenderTableSection>(prevSection);
 }
 
@@ -1381,7 +1375,7 @@
         nextSection = nextSection->nextSibling();
     }
     if (!nextSection && m_foot && (skipEmptySections == DoNotSkipEmptySections || m_foot->numRows()))
-        nextSection = m_foot;
+        nextSection = m_foot.get();
     return downcast<RenderTableSection>(nextSection);
 }
 
@@ -1388,15 +1382,12 @@
 RenderTableSection* RenderTable::bottomSection() const
 {
     recalcSectionsIfNeeded();
-
     if (m_foot)
-        return m_foot;
-
+        return m_foot.get();
     for (RenderObject* child = lastChild(); child; child = child->previousSibling()) {
         if (is<RenderTableSection>(*child))
             return downcast<RenderTableSection>(child);
     }
-
     return nullptr;
 }
 

Modified: trunk/Source/WebCore/rendering/RenderTable.h (222952 => 222953)


--- trunk/Source/WebCore/rendering/RenderTable.h	2017-10-06 02:36:20 UTC (rev 222952)
+++ trunk/Source/WebCore/rendering/RenderTable.h	2017-10-06 02:41:35 UTC (rev 222953)
@@ -153,9 +153,9 @@
         m_columnPos[index] = position;
     }
 
-    RenderTableSection* header() const { return m_head; }
-    RenderTableSection* footer() const { return m_foot; }
-    RenderTableSection* firstBody() const { return m_firstBody; }
+    RenderTableSection* header() const { return m_head.get(); }
+    RenderTableSection* footer() const { return m_foot.get(); }
+    RenderTableSection* firstBody() const { return m_firstBody.get(); }
 
     // This function returns 0 if the table has no section.
     RenderTableSection* topSection() const;
@@ -332,9 +332,9 @@
     typedef HashMap<const RenderTableCol*, unsigned> EffectiveColumnIndexMap;
     mutable EffectiveColumnIndexMap m_effectiveColumnIndexMap;
 
-    mutable RenderTableSection* m_head;
-    mutable RenderTableSection* m_foot;
-    mutable RenderTableSection* m_firstBody;
+    mutable WeakPtr<RenderTableSection> m_head;
+    mutable WeakPtr<RenderTableSection> m_foot;
+    mutable WeakPtr<RenderTableSection> m_firstBody;
 
     std::unique_ptr<TableLayout> m_tableLayout;
 
@@ -372,10 +372,10 @@
 {
     ASSERT(!needsSectionRecalc());
     if (m_head)
-        return m_head;
+        return m_head.get();
     if (m_firstBody)
-        return m_firstBody;
-    return m_foot;
+        return m_firstBody.get();
+    return m_foot.get();
 }
 
 inline bool isDirectionSame(const RenderBox* tableItem, const RenderBox* otherTableItem) { return tableItem && otherTableItem ? tableItem->style().direction() == otherTableItem->style().direction() : true; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to