diff options
author | 2014-11-03 14:34:30 -0800 | |
---|---|---|
committer | 2014-11-03 14:34:31 -0800 | |
commit | fb502f072f5a32ad122bfc2717fe56a3c22e482e (patch) | |
tree | 2a2e7e6149322ac8aca7eded6c6a23792fe07b73 /include/core/SkRect.h | |
parent | 87a94eb1632d06eeeb89490a91565e786440d6d0 (diff) |
Optimize SkRect::sort()
This optimization can reduce comparison and assignments. For
geo_rect_sort benchmark, performance improved to 1.63us from 3.28us.
BUG=skia:
Review URL: https://codereview.chromium.org/695443005
Diffstat (limited to 'include/core/SkRect.h')
-rw-r--r-- | include/core/SkRect.h | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/include/core/SkRect.h b/include/core/SkRect.h index 96bf0f4d90..91765424c7 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -843,15 +843,13 @@ public: * other. When this returns, left <= right && top <= bottom */ 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; + if (fLeft > fRight) { + SkTSwap<SkScalar>(fLeft, fRight); + } + + if (fTop > fBottom) { + SkTSwap<SkScalar>(fTop, fBottom); + } } /** |