summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <ssp@redhat.com>2014-05-29 13:13:32 -0400
committerSøren Sandmann <ssp@redhat.com>2014-05-29 13:13:32 -0400
commit3324036045c0ed092525aaf7eeb5fb2e6ac59579 (patch)
treed08abbc0229aaee5404c2da102464bb116fc7fa6
parentb5d97840b9163927b770aaf84790d60c0de6adaf (diff)
Simplify find_box_for_y()
The new routine is iterative and has simpler logic. Also add some notes about multirows.
-rw-r--r--region-iter.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/region-iter.c b/region-iter.c
index 0d0e2a6..b36ca1b 100644
--- a/region-iter.c
+++ b/region-iter.c
@@ -20,10 +20,15 @@
* We will need a subroutine row_iter_skip_to_y() that will skip
* to the next row with a y2 > y.
*
+ * It may be that the existing row_t type should simply be renamed to
+ * multi_row_t since it's the same API that we'd want.
+ *
* - an iterator that will move backwards through a region and then
* one that will move backwards through a row would be useful for
* scrolling.
*
+ * - test suite
+ *
*/
#include <stdlib.h>
#include <stdio.h>
@@ -452,32 +457,17 @@ region_iter_get_row (region_iter_t *iter, row_t *row)
static pixman_box32_t *
find_box_for_y (pixman_box32_t *begin, pixman_box32_t *end, int y)
{
- pixman_box32_t *mid;
-
- if (end == begin)
- return end;
-
- if (end - begin == 1)
+ while (end - begin > 0)
{
- if (begin->y2 > y)
- return begin;
+ pixman_box32_t *mid = begin + (end - begin) / 2;
+
+ if (mid->y2 > y)
+ end = mid;
else
- return end;
+ begin = mid + 1;
}
- mid = begin + (end - begin) / 2;
- if (mid->y2 > y)
- {
- /* If no box is found in [begin, mid], the function
- * will return @mid, which is then known to be the
- * correct answer.
- */
- return find_box_for_y (begin, mid, y);
- }
- else
- {
- return find_box_for_y (mid, end, y);
- }
+ return end;
}
/* Skips forward to the first row whose y2 > @y */