summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/platform/geometry/Region.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/platform/geometry/Region.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/platform/geometry/Region.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/chromium/third_party/WebKit/Source/platform/geometry/Region.cpp b/chromium/third_party/WebKit/Source/platform/geometry/Region.cpp
index e755a8b1168..ff86e137a51 100644
--- a/chromium/third_party/WebKit/Source/platform/geometry/Region.cpp
+++ b/chromium/third_party/WebKit/Source/platform/geometry/Region.cpp
@@ -207,6 +207,12 @@ bool Region::Shape::compareShapes(const Shape& aShape, const Shape& bShape)
return result;
}
+void Region::Shape::trimCapacities()
+{
+ m_segments.shrinkToReasonableCapacity();
+ m_spans.shrinkToReasonableCapacity();
+}
+
struct Region::Shape::CompareContainsOperation {
const static bool defaultResult = true;
inline static bool aOutsideB(bool& /* result */) { return false; }
@@ -233,6 +239,12 @@ Region::Shape::Shape(const IntRect& rect)
appendSpan(rect.maxY());
}
+Region::Shape::Shape(size_t segmentsCapacity, size_t spansCapacity)
+{
+ m_segments.reserveCapacity(segmentsCapacity);
+ m_spans.reserveCapacity(spansCapacity);
+}
+
void Region::Shape::appendSpan(int y)
{
m_spans.append(Span(y, m_segments.size()));
@@ -393,7 +405,9 @@ Region::Shape Region::Shape::shapeOperation(const Shape& shape1, const Shape& sh
COMPILE_ASSERT(!(!Operation::shouldAddRemainingSegmentsFromSpan1 && Operation::shouldAddRemainingSegmentsFromSpan2), invalid_segment_combination);
COMPILE_ASSERT(!(!Operation::shouldAddRemainingSpansFromShape1 && Operation::shouldAddRemainingSpansFromShape2), invalid_span_combination);
- Shape result;
+ size_t segmentsCapacity = shape1.segmentsSize() + shape2.segmentsSize();
+ size_t spansCapacity = shape1.spansSize() + shape2.spansSize();
+ Shape result(segmentsCapacity, spansCapacity);
if (Operation::trySimpleOperation(shape1, shape2, result))
return result;
@@ -409,6 +423,9 @@ Region::Shape Region::Shape::shapeOperation(const Shape& shape1, const Shape& sh
SegmentIterator segments2 = 0;
SegmentIterator segments2End = 0;
+ Vector<int, 32> segments;
+ segments.reserveCapacity(std::max(shape1.segmentsSize(), shape2.segmentsSize()));
+
// Iterate over all spans.
while (spans1 != spans1End && spans2 != spans2End) {
int y = 0;
@@ -435,7 +452,9 @@ Region::Shape Region::Shape::shapeOperation(const Shape& shape1, const Shape& sh
SegmentIterator s1 = segments1;
SegmentIterator s2 = segments2;
- Vector<int, 32> segments;
+ // Clear vector without dropping capacity.
+ segments.resize(0);
+ ASSERT(segments.capacity());
// Now iterate over the segments in each span and construct a new vector of segments.
while (s1 != segments1End && s2 != segments2End) {
@@ -476,6 +495,8 @@ Region::Shape Region::Shape::shapeOperation(const Shape& shape1, const Shape& sh
else if (Operation::shouldAddRemainingSpansFromShape2 && spans2 != spans2End)
result.appendSpans(shape2, spans2, spans2End);
+ result.trimCapacities();
+
return result;
}