pixman: Branch 'master'

Søren Sandmann Pedersen sandmann at kemper.freedesktop.org
Thu May 21 04:16:42 PDT 2009


 pixman/pixman-region32.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

New commits:
commit cb4085bdb5a40c38209f69c26b3ffe60d08ff4de
Author: Jonathan Morton <jonathan.morton at movial.com>
Date:   Thu May 21 07:16:34 2009 -0400

    Avoid malloc() by allocating a fixed set of boxes on the stack

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;
 }
 


More information about the xorg-commit mailing list