# HG changeset patch # User Thinker K.F. Li # Date 1222308632 -28800 # Node ID 995ee8fd5f1a14d962c8634ae946c3bc3518ffa4 # Parent e96a584487af48f02f22aba1d7a9681fb8bc80c6 Use local static variable to hold position array to reduce using malloc(). diff -r e96a584487af -r 995ee8fd5f1a src/paint.c --- a/src/paint.c Thu Sep 25 09:53:05 2008 +0800 +++ b/src/paint.c Thu Sep 25 10:10:32 2008 +0800 @@ -13,7 +13,7 @@ redraw_man_t *rdman; } paint_color_t; -int paint_color_size = sizeof(paint_color_t); +int _paint_color_size = sizeof(paint_color_t); static void paint_color_prepare(paint_t *paint, cairo_t *cr) { diff -r e96a584487af -r 995ee8fd5f1a src/redraw_man.c --- 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;