diff src/redraw_man.c @ 147:995ee8fd5f1a

Use local static variable to hold position array to reduce using malloc().
author Thinker K.F. Li <thinker@branda.to>
date Thu, 25 Sep 2008 10:10:32 +0800
parents e96a584487af
children fce696643b1e
line wrap: on
line diff
--- a/src/redraw_man.c	Thu Sep 25 09:53:05 2008 +0800
+++ b/src/redraw_man.c	Thu Sep 25 10:10:32 2008 +0800
@@ -196,7 +196,7 @@
 
 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) {
     extern void redraw_man_destroy(redraw_man_t *rdman);
-    extern int paint_color_size;
+    extern int _paint_color_size;
 
     memset(rdman, 0, sizeof(redraw_man_t));
 
@@ -234,7 +234,7 @@
 	return ERR;
     }
 
-    rdman->paint_color_pool = elmpool_new(paint_color_size, 64);
+    rdman->paint_color_pool = elmpool_new(_paint_color_size, 64);
     if(rdman->subject_pool == NULL) {
 	elmpool_free(rdman->geo_pool);
 	elmpool_free(rdman->coord_pool);
@@ -565,10 +565,11 @@
     }
 }
 
-/*! \todo Use a static variable to hold positions array for clean_coord()? */
 static int clean_coord(redraw_man_t *rdman, coord_t *coord) {
     geo_t *geo;
-    co_aix (*poses)[2];
+    /*! \note poses is shared by invokings, it is not support reentrying. */
+    static co_aix (*poses)[2];
+    static int max_poses = 0;
     int cnt, pos_cnt;
 
     setup_canvas(rdman, coord);
@@ -584,9 +585,13 @@
     }
 
     /* Compute area of the coord. */
-    poses = (co_aix (*)[2])malloc(sizeof(co_aix [2]) * 2 * cnt);
-    if(poses == NULL)
-	return ERR;
+    if(max_poses < (cnt * 2)) {
+	free(poses);
+	max_poses = cnt * 2;
+	poses = (co_aix (*)[2])malloc(sizeof(co_aix [2]) * max_poses);
+	if(poses == NULL)
+	    return ERR;
+    }
 
     pos_cnt = 0;
     FORMEMBERS(coord, geo) {
@@ -596,7 +601,6 @@
 
     SWAP(coord->cur_area, coord->last_area, area_t *);
     area_init(coord->cur_area, pos_cnt, poses);
-    free(poses);
     
     coord->flags &= ~COF_DIRTY;