Remove TreeOrderIterator and iterate over the child boxes directly.
authorojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Feb 2012 01:15:16 +0000 (01:15 +0000)
committerojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Feb 2012 01:15:16 +0000 (01:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78294

Reviewed by Tony Chang.

No new tests. This is purely a refactor. No change in behavior.

* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutFlexItems):
(WebCore::RenderFlexibleBox::computeMainAxisPreferredSizes):
* rendering/RenderFlexibleBox.h:
(RenderFlexibleBox):
(FlexOrderHashTraits):
(WebCore::RenderFlexibleBox::FlexOrderHashTraits::emptyValue):
(WebCore::RenderFlexibleBox::FlexOrderHashTraits::constructDeletedValue):
(WebCore::RenderFlexibleBox::FlexOrderHashTraits::isDeletedValue):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderFlexibleBox.cpp
Source/WebCore/rendering/RenderFlexibleBox.h

index c9d7a04..5193249 100644 (file)
@@ -1,3 +1,22 @@
+2012-02-09  Ojan Vafai  <ojan@chromium.org>
+
+        Remove TreeOrderIterator and iterate over the child boxes directly.
+        https://bugs.webkit.org/show_bug.cgi?id=78294
+
+        Reviewed by Tony Chang.
+
+        No new tests. This is purely a refactor. No change in behavior. 
+
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::RenderFlexibleBox::layoutFlexItems):
+        (WebCore::RenderFlexibleBox::computeMainAxisPreferredSizes):
+        * rendering/RenderFlexibleBox.h:
+        (RenderFlexibleBox):
+        (FlexOrderHashTraits):
+        (WebCore::RenderFlexibleBox::FlexOrderHashTraits::emptyValue):
+        (WebCore::RenderFlexibleBox::FlexOrderHashTraits::constructDeletedValue):
+        (WebCore::RenderFlexibleBox::FlexOrderHashTraits::isDeletedValue):
+
 2012-02-09  Kentaro Hara  <haraken@chromium.org>
 
         Code generators should support multiple values for the [CallWith=] attribute
index bfe1db0..9fa5660 100644 (file)
@@ -40,55 +40,13 @@ namespace WebCore {
 // Normally, -1 and 0 are not valid in a HashSet, but these are relatively likely flex-order values. Instead,
 // we make the two smallest int values invalid flex-order values (in the css parser code we clamp them to
 // int min + 2).
-struct FlexOrderHashTraits : WTF::GenericHashTraits<int> {
+struct RenderFlexibleBox::FlexOrderHashTraits : WTF::GenericHashTraits<int> {
     static const bool emptyValueIsZero = false;
     static int emptyValue() { return std::numeric_limits<int>::min(); }
     static void constructDeletedValue(int& slot) { slot = std::numeric_limits<int>::min() + 1; }
     static bool isDeletedValue(int value) { return value == std::numeric_limits<int>::min() + 1; }
 };
 
-typedef HashSet<int, DefaultHash<int>::Hash, FlexOrderHashTraits> FlexOrderHashSet;
-
-class RenderFlexibleBox::TreeOrderIterator {
-public:
-    explicit TreeOrderIterator(RenderFlexibleBox* flexibleBox)
-        : m_flexibleBox(flexibleBox)
-        , m_currentChild(0)
-    {
-    }
-
-    RenderBox* first()
-    {
-        reset();
-        return next();
-    }
-
-    RenderBox* next()
-    {
-        m_currentChild = m_currentChild ? m_currentChild->nextSiblingBox() : m_flexibleBox->firstChildBox();
-
-        if (m_currentChild)
-            m_flexOrderValues.add(m_currentChild->style()->flexOrder());
-
-        return m_currentChild;
-    }
-
-    void reset()
-    {
-        m_currentChild = 0;
-    }
-
-    const FlexOrderHashSet& flexOrderValues()
-    {
-        return m_flexOrderValues;
-    }
-
-private:
-    RenderFlexibleBox* m_flexibleBox;
-    RenderBox* m_currentChild;
-    FlexOrderHashSet m_flexOrderValues;
-};
-
 class RenderFlexibleBox::FlexOrderIterator {
 public:
     FlexOrderIterator(RenderFlexibleBox* flexibleBox, const FlexOrderHashSet& flexOrderValues)
@@ -465,14 +423,14 @@ LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox*
 
 void RenderFlexibleBox::layoutFlexItems(bool relayoutChildren)
 {
-    TreeOrderIterator treeIterator(this);
-    computeMainAxisPreferredSizes(relayoutChildren, treeIterator);
+    FlexOrderHashSet flexOrderValues;
+    computeMainAxisPreferredSizes(relayoutChildren, flexOrderValues);
 
     OrderedFlexItemList orderedChildren;
     LayoutUnit preferredMainAxisExtent;
     float totalPositiveFlexibility;
     float totalNegativeFlexibility;
-    FlexOrderIterator flexIterator(this, treeIterator.flexOrderValues());
+    FlexOrderIterator flexIterator(this, flexOrderValues);
     computeFlexOrder(flexIterator, orderedChildren, preferredMainAxisExtent, totalPositiveFlexibility, totalNegativeFlexibility);
 
     LayoutUnit availableFreeSpace = mainAxisContentExtent() - preferredMainAxisExtent;
@@ -511,10 +469,12 @@ LayoutUnit RenderFlexibleBox::marginBoxAscent(RenderBox* child)
     return ascent + flowAwareMarginBeforeForChild(child);
 }
 
-void RenderFlexibleBox::computeMainAxisPreferredSizes(bool relayoutChildren, TreeOrderIterator& iterator)
+void RenderFlexibleBox::computeMainAxisPreferredSizes(bool relayoutChildren, FlexOrderHashSet& flexOrderValues)
 {
     LayoutUnit flexboxAvailableContentExtent = mainAxisContentExtent();
-    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
+    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
+        flexOrderValues.add(child->style()->flexOrder());
+
         if (child->isPositioned())
             continue;
 
index 72dbdcb..48e9fb5 100644 (file)
@@ -49,7 +49,9 @@ public:
     bool isHorizontalFlow() const;
 
 private:
-    class TreeOrderIterator;
+    struct FlexOrderHashTraits;
+    typedef HashSet<int, DefaultHash<int>::Hash, FlexOrderHashTraits> FlexOrderHashSet;
+
     class FlexOrderIterator;
     typedef WTF::HashMap<const RenderBox*, LayoutUnit> InflexibleFlexItemSize;
     typedef WTF::Vector<RenderBox*> OrderedFlexItemList;
@@ -96,7 +98,7 @@ private:
     LayoutUnit availableAlignmentSpaceForChild(RenderBox*);
     LayoutUnit marginBoxAscent(RenderBox*);
 
-    void computeMainAxisPreferredSizes(bool relayoutChildren, TreeOrderIterator&);
+    void computeMainAxisPreferredSizes(bool relayoutChildren, FlexOrderHashSet&);
     void computeFlexOrder(FlexOrderIterator&, OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, float& totalPositiveFlexibility, float& totalNegativeFlexibility);
     bool runFreeSpaceAllocationAlgorithm(const OrderedFlexItemList&, LayoutUnit& availableFreeSpace, float& totalPositiveFlexibility, float& totalNegativeFlexibility, InflexibleFlexItemSize&, WTF::Vector<LayoutUnit>& childSizes);
     void setLogicalOverrideSize(RenderBox* child, LayoutUnit childPreferredSize);