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

Side by Side Diff: Source/platform/geometry/Region.h

Issue 183663030: Reduce number of vector buffer reallocs in Regions::unite . (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased patch. Created 6 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/platform/geometry/Region.cpp » ('j') | Source/platform/geometry/Region.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 int y; 73 int y;
74 size_t segmentIndex; 74 size_t segmentIndex;
75 }; 75 };
76 76
77 class Shape { 77 class Shape {
78 public: 78 public:
79 Shape(); 79 Shape();
80 Shape(const IntRect&); 80 Shape(const IntRect&);
81 Shape(size_t segmentsCapacity, size_t spansCapacity);
81 82
82 IntRect bounds() const; 83 IntRect bounds() const;
83 bool isEmpty() const { return m_spans.isEmpty(); } 84 bool isEmpty() const { return m_spans.isEmpty(); }
84 bool isRect() const { return m_spans.size() <= 2 && m_segments.size() <= 2; } 85 bool isRect() const { return m_spans.size() <= 2 && m_segments.size() <= 2; }
85 86
86 typedef const Span* SpanIterator; 87 typedef const Span* SpanIterator;
87 SpanIterator spansBegin() const; 88 SpanIterator spansBegin() const;
88 SpanIterator spansEnd() const; 89 SpanIterator spansEnd() const;
90 size_t spansSize() const { return m_spans.size(); }
89 91
90 typedef const int* SegmentIterator; 92 typedef const int* SegmentIterator;
91 SegmentIterator segmentsBegin(SpanIterator) const; 93 SegmentIterator segmentsBegin(SpanIterator) const;
92 SegmentIterator segmentsEnd(SpanIterator) const; 94 SegmentIterator segmentsEnd(SpanIterator) const;
95 size_t segmentsSize() const { return m_segments.size(); }
93 96
94 static Shape unionShapes(const Shape& shape1, const Shape& shape2); 97 static Shape unionShapes(const Shape& shape1, const Shape& shape2);
95 static Shape intersectShapes(const Shape& shape1, const Shape& shape2); 98 static Shape intersectShapes(const Shape& shape1, const Shape& shape2);
96 static Shape subtractShapes(const Shape& shape1, const Shape& shape2); 99 static Shape subtractShapes(const Shape& shape1, const Shape& shape2);
97 100
98 void translate(const IntSize&); 101 void translate(const IntSize&);
99 void swap(Shape&); 102 void swap(Shape&);
100 103
101 struct CompareContainsOperation; 104 struct CompareContainsOperation;
102 struct CompareIntersectsOperation; 105 struct CompareIntersectsOperation;
103 106
104 template<typename CompareOperation> 107 template<typename CompareOperation>
105 static bool compareShapes(const Shape& shape1, const Shape& shape2); 108 static bool compareShapes(const Shape& shape1, const Shape& shape2);
109 void trimCapacities();
106 110
107 #ifndef NDEBUG 111 #ifndef NDEBUG
108 void dump() const; 112 void dump() const;
109 #endif 113 #endif
110 114
111 private: 115 private:
112 struct UnionOperation; 116 struct UnionOperation;
113 struct IntersectOperation; 117 struct IntersectOperation;
114 struct SubtractOperation; 118 struct SubtractOperation;
115 119
116 template<typename Operation> 120 template<typename Operation>
117 static Shape shapeOperation(const Shape& shape1, const Shape& shape2); 121 static Shape shapeOperation(const Shape& shape1, const Shape& shape2);
118 122
119 void appendSegment(int x); 123 void appendSegment(int x);
120 void appendSpan(int y); 124 void appendSpan(int y);
121 void appendSpan(int y, SegmentIterator begin, SegmentIterator end); 125 void appendSpan(int y, SegmentIterator begin, SegmentIterator end);
122 void appendSpans(const Shape&, SpanIterator begin, SpanIterator end); 126 void appendSpans(const Shape&, SpanIterator begin, SpanIterator end);
123 127
124 bool canCoalesce(SegmentIterator begin, SegmentIterator end); 128 bool canCoalesce(SegmentIterator begin, SegmentIterator end);
125 129
126 Vector<int, 32> m_segments; 130 static const size_t segmentsDefaultCapacity = 32;
127 Vector<Span, 16> m_spans; 131 static const size_t segmentsMask = segmentsDefaultCapacity - 1;
132 Vector<int, segmentsDefaultCapacity> m_segments;
133 static const size_t spansDefaultCapacity = 16;
134 static const size_t spansMask = spansDefaultCapacity - 1;
135 Vector<Span, spansDefaultCapacity> m_spans;
128 136
129 friend bool operator==(const Shape&, const Shape&); 137 friend bool operator==(const Shape&, const Shape&);
130 }; 138 };
131 139
132 IntRect m_bounds; 140 IntRect m_bounds;
133 Shape m_shape; 141 Shape m_shape;
134 142
135 friend bool operator==(const Region&, const Region&); 143 friend bool operator==(const Region&, const Region&);
136 friend bool operator==(const Shape&, const Shape&); 144 friend bool operator==(const Shape&, const Shape&);
137 friend bool operator==(const Span&, const Span&); 145 friend bool operator==(const Span&, const Span&);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 180 }
173 181
174 inline bool operator==(const Region::Span& a, const Region::Span& b) 182 inline bool operator==(const Region::Span& a, const Region::Span& b)
175 { 183 {
176 return a.y == b.y && a.segmentIndex == b.segmentIndex; 184 return a.y == b.y && a.segmentIndex == b.segmentIndex;
177 } 185 }
178 186
179 } // namespace WebCore 187 } // namespace WebCore
180 188
181 #endif // Region_h 189 #endif // Region_h
OLDNEW
« no previous file with comments | « no previous file | Source/platform/geometry/Region.cpp » ('j') | Source/platform/geometry/Region.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698