diff options
author | Raul Fernandes <rgfernandes@gmail.com> | 2013-08-08 09:26:59 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2013-08-08 09:28:20 +0100 |
commit | c6add09791a44d9b3af79d50f52e6913c46341a8 (patch) | |
tree | 5258afe1b63d31997305011d358d374d2abf2293 /src/sna | |
parent | c01c66bca2c64ae2d77233b6ccdca26431ee51b8 (diff) |
Micro-optimise box intersections
We can shave a few instructions off the routine by incrementally
performing the "is-empty" check as soon as we compute the intersection
in each dimension.
Diffstat (limited to 'src/sna')
-rw-r--r-- | src/sna/fb/fbclip.h | 7 | ||||
-rw-r--r-- | src/sna/sna.h | 7 | ||||
-rw-r--r-- | src/sna/sna_display.c | 8 |
3 files changed, 19 insertions, 3 deletions
diff --git a/src/sna/fb/fbclip.h b/src/sna/fb/fbclip.h index f07e63ca..554aeb39 100644 --- a/src/sna/fb/fbclip.h +++ b/src/sna/fb/fbclip.h @@ -38,12 +38,17 @@ box_intersect(BoxPtr a, const BoxRec *b) a->x1 = b->x1; if (a->x2 > b->x2) a->x2 = b->x2; + if (a->x1 >= a->x2) + return false; + if (a->y1 < b->y1) a->y1 = b->y1; if (a->y2 > b->y2) a->y2 = b->y2; + if (a->y1 >= a->y2) + return false; - return a->x1 < a->x2 && a->y1 < a->y2; + return true; } #define run_box(b, c) \ diff --git a/src/sna/sna.h b/src/sna/sna.h index abc8c5bf..caf671f3 100644 --- a/src/sna/sna.h +++ b/src/sna/sna.h @@ -895,12 +895,17 @@ box_intersect(BoxPtr a, const BoxRec *b) a->x1 = b->x1; if (a->x2 > b->x2) a->x2 = b->x2; + if (a->x1 >= a->x2) + return false; + if (a->y1 < b->y1) a->y1 = b->y1; if (a->y2 > b->y2) a->y2 = b->y2; + if (a->y1 >= a->y2) + return false; - return a->x1 < a->x2 && a->y1 < a->y2; + return true; } unsigned sna_cpu_detect(void); diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c index f13b4234..5dcf47fa 100644 --- a/src/sna/sna_display.c +++ b/src/sna/sna_display.c @@ -3213,6 +3213,9 @@ static bool sna_box_intersect(BoxPtr r, const BoxRec *a, const BoxRec *b) { r->x1 = a->x1 > b->x1 ? a->x1 : b->x1; r->x2 = a->x2 < b->x2 ? a->x2 : b->x2; + if (r->x1 >= r->x2) + return false; + r->y1 = a->y1 > b->y1 ? a->y1 : b->y1; r->y2 = a->y2 < b->y2 ? a->y2 : b->y2; DBG(("%s: (%d, %d), (%d, %d) intersect (%d, %d), (%d, %d) = (%d, %d), (%d, %d)\n", @@ -3220,7 +3223,10 @@ static bool sna_box_intersect(BoxPtr r, const BoxRec *a, const BoxRec *b) a->x1, a->y1, a->x2, a->y2, b->x1, b->y1, b->x2, b->y2, r->x1, r->y1, r->x2, r->y2)); - return r->x2 > r->x1 && r->y2 > r->y1; + if (r->y1 >= r->y2) + return false; + + return true; } static int sna_box_area(const BoxRec *box) |