Chromium Code Reviews| Index: Source/platform/geometry/Region.cpp |
| diff --git a/Source/platform/geometry/Region.cpp b/Source/platform/geometry/Region.cpp |
| index e755a8b11680dd3f5ecb5ff72de35b373958d9a2..addc038b0a806db8e518573d682ebb5e72f399f4 100644 |
| --- a/Source/platform/geometry/Region.cpp |
| +++ b/Source/platform/geometry/Region.cpp |
| @@ -233,6 +233,28 @@ Region::Shape::Shape(const IntRect& rect) |
| appendSpan(rect.maxY()); |
| } |
| +Region::Shape::Shape(size_t segmentsCapacity, size_t spansCapacity) |
| +{ |
| + if (segmentsCapacity > m_segments.capacity()) { |
| + segmentsCapacity = (segmentsCapacity + segmentsMask) & ~segmentsMask; |
| + m_segments.reserveCapacity(segmentsCapacity); |
| + } |
| + |
| + if (spansCapacity > m_spans.capacity()) { |
| + spansCapacity = (spansCapacity + spansMask) & ~spansMask; |
| + m_spans.reserveCapacity(spansCapacity); |
| + } |
| +} |
| + |
| +void Region::Shape::trimCapacities() |
|
danakj
2014/04/09 18:39:51
Methods in the same order as their declarations in
ostap
2014/04/09 22:45:43
It seems that all other methods are not in the sam
|
| +{ |
| + if (m_segments.size() > segmentsDefaultCapacity && m_segments.capacity() > m_segments.size() * 2) |
| + m_segments.shrinkToFit(); |
|
danakj
2014/04/09 18:39:51
I feel like this is kinda unfortunate, in that you
ostap
2014/04/09 22:45:43
Region always allocate new buffers for operation.
danakj
2014/04/15 20:15:43
Wanna add that to the CL and we'll see what OWNERs
|
| + |
| + if (m_spans.size() > spansDefaultCapacity && m_spans.capacity() > m_spans.size() * 2) |
| + m_spans.shrinkToFit(); |
| +} |
| + |
| void Region::Shape::appendSpan(int y) |
| { |
| m_spans.append(Span(y, m_segments.size())); |
| @@ -393,7 +415,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 +433,8 @@ Region::Shape Region::Shape::shapeOperation(const Shape& shape1, const Shape& sh |
| SegmentIterator segments2 = 0; |
| SegmentIterator segments2End = 0; |
| + Vector<int, segmentsDefaultCapacity> segments; |
|
danakj
2014/04/09 18:39:51
would it improve anything further in your benchmar
ostap
2014/04/09 22:45:43
No, no change at all.
But this benchmark is very s
|
| + |
| // Iterate over all spans. |
| while (spans1 != spans1End && spans2 != spans2End) { |
| int y = 0; |
| @@ -432,11 +458,12 @@ Region::Shape Region::Shape::shapeOperation(const Shape& shape1, const Shape& sh |
| int flag = 0; |
| int oldFlag = 0; |
| + // clear vector without dropping capacity |
|
danakj
2014/04/09 18:39:51
nit: proper sentence (capitalized, with period at
ostap
2014/04/09 22:45:43
Done.
|
| + segments.resize(0); |
|
danakj
2014/04/09 18:39:51
keep this in the same position? (below s1,s2 assig
ostap
2014/04/09 22:45:43
Done.
|
| + |
| SegmentIterator s1 = segments1; |
| SegmentIterator s2 = segments2; |
| - Vector<int, 32> segments; |
| - |
| // Now iterate over the segments in each span and construct a new vector of segments. |
| while (s1 != segments1End && s2 != segments2End) { |
| int test = *s1 - *s2; |
| @@ -476,6 +503,9 @@ Region::Shape Region::Shape::shapeOperation(const Shape& shape1, const Shape& sh |
| else if (Operation::shouldAddRemainingSpansFromShape2 && spans2 != spans2End) |
| result.appendSpans(shape2, spans2, spans2End); |
| + // Trim excess capacities if necessary. |
|
danakj
2014/04/09 18:39:51
Prefer not to add comments that just repeat the na
ostap
2014/04/09 22:45:43
Done.
|
| + result.trimCapacities(); |
| + |
| return result; |
| } |