aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2014-10-10 05:50:15 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-10 05:50:15 -0700
commit40636a53037eadd957b8e43f0961f640aaa93e84 (patch)
treeddd687900a7bb6965c63e97663deefd7c11f0015
parent0ad24bee47e734b1a8f86f40d7eb240cc20c618c (diff)
faster SkRect::sort
-rw-r--r--bench/GeometryBench.cpp18
-rw-r--r--include/core/SkRect.h14
-rw-r--r--src/core/SkRect.cpp9
3 files changed, 28 insertions, 13 deletions
diff --git a/bench/GeometryBench.cpp b/bench/GeometryBench.cpp
index cd58e3cdaf..a5c4643f9e 100644
--- a/bench/GeometryBench.cpp
+++ b/bench/GeometryBench.cpp
@@ -97,7 +97,7 @@ protected:
class GeoRectBench_Intersects : public GeoRectBench {
public:
GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {}
-
+
protected:
virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
for (int outer = 0; outer < loops; ++outer) {
@@ -110,6 +110,22 @@ protected:
}
};
+class GeoRectBench_sort : public GeoRectBench {
+public:
+ GeoRectBench_sort() : GeoRectBench("rect_sort") {}
+
+protected:
+ virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
+ for (int outer = 0; outer < loops; ++outer) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
+ fRects[i].sort();
+ }
+ }
+ }
+};
+
DEF_BENCH( return new GeoRectBench_intersect; )
DEF_BENCH( return new GeoRectBench_intersect_rect; )
DEF_BENCH( return new GeoRectBench_Intersects; )
+
+DEF_BENCH( return new GeoRectBench_sort; )
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index d9ef7a5ecf..995beb8662 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -6,7 +5,6 @@
* found in the LICENSE file.
*/
-
#ifndef SkRect_DEFINED
#define SkRect_DEFINED
@@ -842,7 +840,17 @@ public:
* if the edges are computed separately, and may have crossed over each
* other. When this returns, left <= right && top <= bottom
*/
- void sort();
+ void sort() {
+ SkScalar min = SkMinScalar(fLeft, fRight);
+ SkScalar max = SkMaxScalar(fLeft, fRight);
+ fLeft = min;
+ fRight = max;
+
+ min = SkMinScalar(fTop, fBottom);
+ max = SkMaxScalar(fTop, fBottom);
+ fTop = min;
+ fBottom = max;
+ }
/**
* cast-safe way to treat the rect as an array of (4) SkScalars.
diff --git a/src/core/SkRect.cpp b/src/core/SkRect.cpp
index 7340098d2f..fbf03efe89 100644
--- a/src/core/SkRect.cpp
+++ b/src/core/SkRect.cpp
@@ -37,15 +37,6 @@ void SkIRect::sort() {
/////////////////////////////////////////////////////////////////////////////
-void SkRect::sort() {
- if (fLeft > fRight) {
- SkTSwap<SkScalar>(fLeft, fRight);
- }
- if (fTop > fBottom) {
- SkTSwap<SkScalar>(fTop, fBottom);
- }
-}
-
void SkRect::toQuad(SkPoint quad[4]) const {
SkASSERT(quad);