Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(921)

Unified Diff: Source/core/rendering/RenderFlexibleBox.cpp

Issue 18133003: Get rid of the extra vector when setting up the orderIterator. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/rendering/RenderFlexibleBox.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/RenderFlexibleBox.cpp
diff --git a/Source/core/rendering/RenderFlexibleBox.cpp b/Source/core/rendering/RenderFlexibleBox.cpp
index 082cddc3ba0757060b60bad414667fb227fd0af5..0cfc288ced8a205750ed4db5ffdc0a3fd6072303 100644
--- a/Source/core/rendering/RenderFlexibleBox.cpp
+++ b/Source/core/rendering/RenderFlexibleBox.cpp
@@ -46,35 +46,6 @@ RenderFlexibleBox::OrderIterator::OrderIterator(const RenderFlexibleBox* flexibl
{
}
-void RenderFlexibleBox::OrderIterator::setOrderValues(Vector<int>& orderValues)
-{
- reset();
- m_orderValues.clear();
-
- if (orderValues.isEmpty())
- return;
-
- std::sort(orderValues.begin(), orderValues.end());
-
-
- // This is inefficient if there are many repeated values, but
- // saves a lot of allocations when the values are unique. By far,
- // the common case is that there's exactly one item in the list
- // (the default order value of 0).
- m_orderValues.reserveInitialCapacity(orderValues.size());
-
- int previous = orderValues[0];
- m_orderValues.append(previous);
- for (size_t i = 1; i < orderValues.size(); ++i) {
- int current = orderValues[i];
- if (current == previous)
- continue;
- m_orderValues.append(current);
- previous = current;
- }
- m_orderValues.shrinkToFit();
-}
-
RenderBox* RenderFlexibleBox::OrderIterator::first()
{
reset();
@@ -362,13 +333,12 @@ void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit)
RenderBlock::startDelayUpdateScrollInfo();
- Vector<LineContext> lineContexts;
- Vector<int> orderValues;
- computeMainAxisPreferredSizes(orderValues);
- m_orderIterator.setOrderValues(orderValues);
+ prepareOrderIteratorAndMargins();
ChildFrameRects oldChildRects;
appendChildFrameRects(oldChildRects);
+
+ Vector<LineContext> lineContexts;
layoutFlexItems(relayoutChildren, lineContexts);
updateLogicalHeight();
@@ -939,15 +909,18 @@ LayoutUnit RenderFlexibleBox::computeChildMarginValue(Length margin, RenderView*
return minimumValueForLength(margin, availableSize, view);
}
-void RenderFlexibleBox::computeMainAxisPreferredSizes(Vector<int>& orderValues)
+void RenderFlexibleBox::prepareOrderIteratorAndMargins()
{
RenderView* renderView = view();
bool anyChildHasDefaultOrderValue = false;
+ m_orderIterator.reset();
+ m_orderIterator.m_orderValues.resize(0);
+
for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
// Avoid growing the vector for the common-case default value of 0.
if (int order = child->style()->order())
- orderValues.append(child->style()->order());
+ m_orderIterator.m_orderValues.append(child->style()->order());
else
anyChildHasDefaultOrderValue = true;
@@ -967,10 +940,26 @@ void RenderFlexibleBox::computeMainAxisPreferredSizes(Vector<int>& orderValues)
if (anyChildHasDefaultOrderValue) {
// Avoid growing the vector to the default capacity of 16 if we're only going to put one item in it.
- if (orderValues.isEmpty())
- orderValues.reserveInitialCapacity(1);
- orderValues.append(0);
+ if (m_orderIterator.m_orderValues.isEmpty())
+ m_orderIterator.m_orderValues.reserveInitialCapacity(1);
+ m_orderIterator.m_orderValues.append(0);
+ } else if (m_orderIterator.m_orderValues.isEmpty()) {
+ m_orderIterator.m_orderValues.clear();
+ return;
+ }
+
+ std::sort(m_orderIterator.m_orderValues.begin(), m_orderIterator.m_orderValues.end());
+
+ int previous = m_orderIterator.m_orderValues[0];
+ int uniqueCount = 1;
+ for (size_t i = 1; i < m_orderIterator.m_orderValues.size(); ++i) {
+ int current = m_orderIterator.m_orderValues[i];
+ if (current == previous)
+ continue;
+ m_orderIterator.m_orderValues[uniqueCount++] = current;
+ previous = current;
}
+ m_orderIterator.m_orderValues.shrinkCapacity(uniqueCount);
}
LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox* child, LayoutUnit childSize)
« no previous file with comments | « Source/core/rendering/RenderFlexibleBox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698