diff options
author | Jonathan Morton <jonathan.morton@movial.com> | 2009-05-21 07:16:34 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <sandmann@redhat.com> | 2009-05-21 07:16:34 -0400 |
commit | cb4085bdb5a40c38209f69c26b3ffe60d08ff4de (patch) | |
tree | 5340702432a1bc5c1afccf5aa82eb32445903b30 | |
parent | 5424d0245b28dff81032341a60dea1dd70c594b7 (diff) |
Avoid malloc() by allocating a fixed set of boxes on the stack
-rw-r--r-- | pixman/pixman-region32.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/pixman/pixman-region32.c b/pixman/pixman-region32.c index 8a30d1d..aac74f6 100644 --- a/pixman/pixman-region32.c +++ b/pixman/pixman-region32.c @@ -40,6 +40,8 @@ typedef struct { #define PREFIX(x) pixman_region32##x +#define N_TMP_BOXES (16) + pixman_bool_t pixman_region32_copy_from_region16 (pixman_region32_t *dst, pixman_region16_t *src) @@ -47,12 +49,16 @@ pixman_region32_copy_from_region16 (pixman_region32_t *dst, int n_boxes, i; pixman_box16_t *boxes16; pixman_box32_t *boxes32; + pixman_box32_t tmp_boxes[N_TMP_BOXES]; pixman_bool_t retval; boxes16 = pixman_region_rectangles (src, &n_boxes); - boxes32 = pixman_malloc_ab (n_boxes, sizeof (pixman_box32_t)); - + if (n_boxes > N_TMP_BOXES) + boxes32 = pixman_malloc_ab (n_boxes, sizeof (pixman_box32_t)); + else + boxes32 = tmp_boxes; + if (!boxes32) return FALSE; @@ -66,7 +72,10 @@ pixman_region32_copy_from_region16 (pixman_region32_t *dst, pixman_region32_fini (dst); retval = pixman_region32_init_rects (dst, boxes32, n_boxes); - free (boxes32); + + if (boxes32 != tmp_boxes) + free (boxes32); + return retval; } |