Add a cache of images to reduce malloc/free time
authorSøren Sandmann Pedersen <sandmann@redhat.com>
Tue, 19 Jun 2007 16:41:21 +0000 (12:41 -0400)
committerSøren Sandmann Pedersen <sandmann@redhat.com>
Tue, 19 Jun 2007 16:41:21 +0000 (12:41 -0400)
pixman/pixman-image.c
pixman/pixman-private.h

index 2bc3ef6..bd50705 100644 (file)
@@ -69,10 +69,37 @@ color_to_uint32 (const pixman_color_t *color)
        (color->blue >> 8);
 }
 
+static pixman_image_t *image_cache;
+
+static pixman_image_t *
+new_image (void)
+{
+    pixman_image_t *image;
+
+    if (image_cache)
+    {
+       image = image_cache;
+       image_cache = image->next;
+    }
+    else
+    {
+       image = malloc (sizeof (pixman_image_t));
+    }
+
+    return image;
+}
+
+static void
+delete_image (pixman_image_t *image)
+{
+    image->next = image_cache;
+    image_cache = image;
+}
+
 static pixman_image_t *
 allocate_image (void)
 {
-    pixman_image_t *image = malloc (sizeof (pixman_image_t));
+    pixman_image_t *image = new_image();
     
     if (image)
     {
@@ -145,7 +172,7 @@ pixman_image_unref (pixman_image_t *image)
        if (image->type == BITS && image->bits.free_me)
            free (image->bits.free_me);
        
-       free (image);
+       delete_image (image);
     }
 }
 
index 9b89dee..d10d7ad 100644 (file)
@@ -260,6 +260,7 @@ union pixman_image
     conical_gradient_t         conical;
     radial_gradient_t          radial;
     solid_fill_t               solid;
+    pixman_image_t             *next;  /* Used in the image cache */
 };
 
 #define LOG2_BITMAP_PAD 5