From 1578530557481346f98f449d0f2885a7c985a222 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 23 Jul 2011 19:45:30 +0100 Subject: [PATCH] region: Directly handle single rectangle creation in create_rectangles() In order to avoid the copy and transformation of the single rectangle, we can simply pass it to pixman and create the region from it. Signed-off-by: Chris Wilson --- src/cairo-region.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cairo-region.c b/src/cairo-region.c index 5e29bfe17..f3ccb898a 100644 --- a/src/cairo-region.c +++ b/src/cairo-region.c @@ -236,6 +236,17 @@ cairo_region_create_rectangles (const cairo_rectangle_int_t *rects, if (unlikely (region == NULL)) return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); + CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); + region->status = CAIRO_STATUS_SUCCESS; + + if (count == 1) { + pixman_region32_init_rect (®ion->rgn, + rects->x, rects->y, + rects->width, rects->height); + + return region; + } + if (count > ARRAY_LENGTH (stack_pboxes)) { pboxes = _cairo_malloc_ab (count, sizeof (pixman_box32_t)); if (unlikely (pboxes == NULL)) { @@ -261,8 +272,6 @@ cairo_region_create_rectangles (const cairo_rectangle_int_t *rects, return _cairo_region_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); } - CAIRO_REFERENCE_COUNT_INIT (®ion->ref_count, 1); - region->status = CAIRO_STATUS_SUCCESS; return region; } slim_hidden_def (cairo_region_create_rectangles);