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
This commit is contained in:
qiankun.miao 2014-11-03 14:34:30 -08:00 committed by Commit bot
parent 87a94eb163
commit fb502f072f

View File

@ -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);
}
}
/**