aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkRTree.h
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-30 21:01:26 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-30 21:01:26 +0000
commite83e994da4add978d1b7f0bc9d6df6099098a55b (patch)
treeee4f6fa405a6d6b5ca8ace7097b21dc5f79d4833 /src/core/SkRTree.h
parent5b33211c5edafde82af781beaa1dbc295000a62f (diff)
Avoid possible O(n) stack space use by skqsort.
Diffstat (limited to 'src/core/SkRTree.h')
-rw-r--r--src/core/SkRTree.h35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/core/SkRTree.h b/src/core/SkRTree.h
index 139cc61b76..0a536677cd 100644
--- a/src/core/SkRTree.h
+++ b/src/core/SkRTree.h
@@ -119,19 +119,28 @@ private:
typedef int32_t SkIRect::*SortSide;
// Helper for sorting our children arrays by sides of their rects
- static bool RectLessThan(SortSide const& side, const Branch lhs, const Branch rhs) {
- return lhs.fBounds.*side < rhs.fBounds.*side;
- }
-
- static bool RectLessX(int&, const Branch lhs, const Branch rhs) {
- return ((lhs.fBounds.fRight - lhs.fBounds.fLeft) >> 1) <
- ((rhs.fBounds.fRight - lhs.fBounds.fLeft) >> 1);
- }
-
- static bool RectLessY(int&, const Branch lhs, const Branch rhs) {
- return ((lhs.fBounds.fBottom - lhs.fBounds.fTop) >> 1) <
- ((rhs.fBounds.fBottom - lhs.fBounds.fTop) >> 1);
- }
+ struct RectLessThan {
+ RectLessThan(SkRTree::SortSide side) : fSide(side) { }
+ bool operator()(const SkRTree::Branch lhs, const SkRTree::Branch rhs) const {
+ return lhs.fBounds.*fSide < rhs.fBounds.*fSide;
+ }
+ private:
+ const SkRTree::SortSide fSide;
+ };
+
+ struct RectLessX {
+ bool operator()(const SkRTree::Branch lhs, const SkRTree::Branch rhs) {
+ return ((lhs.fBounds.fRight - lhs.fBounds.fLeft) >> 1) <
+ ((rhs.fBounds.fRight - lhs.fBounds.fLeft) >> 1);
+ }
+ };
+
+ struct RectLessY {
+ bool operator()(const SkRTree::Branch lhs, const SkRTree::Branch rhs) {
+ return ((lhs.fBounds.fBottom - lhs.fBounds.fTop) >> 1) <
+ ((rhs.fBounds.fBottom - lhs.fBounds.fTop) >> 1);
+ }
+ };
SkRTree(int minChildren, int maxChildren, SkScalar aspectRatio);