Mercurial > MadButterfly
changeset 865:48df0f97f09e
Allocate sh_path_t objects from an elmpool
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 23 Sep 2010 09:55:37 +0800 |
parents | 6eaeec6806f2 |
children | 9a7ac4487849 |
files | include/mb_redraw_man.h src/redraw_man.c src/shape_path.c |
diffstat | 3 files changed, 38 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_redraw_man.h Wed Sep 22 21:14:06 2010 +0800 +++ b/include/mb_redraw_man.h Thu Sep 23 09:55:37 2010 +0800 @@ -50,6 +50,7 @@ elmpool_t *geo_pool; elmpool_t *coord_pool; elmpool_t *shnode_pool; + elmpool_t *sh_path_pool; elmpool_t *observer_pool; elmpool_t *subject_pool; elmpool_t *paint_color_pool;
--- a/src/redraw_man.c Wed Sep 22 21:14:06 2010 +0800 +++ b/src/redraw_man.c Thu Sep 23 09:55:37 2010 +0800 @@ -639,6 +639,7 @@ int redraw_man_init(redraw_man_t *rdman, mbe_t *cr, mbe_t *backend) { extern void redraw_man_destroy(redraw_man_t *rdman); + extern int _sh_path_size; extern int _paint_color_size; observer_t *addrm_ob; extern void addrm_monitor_hdlr(event_t *evt, void *arg); @@ -653,6 +654,7 @@ rdman->geo_pool = elmpool_new(sizeof(geo_t), 128); rdman->coord_pool = elmpool_new(sizeof(coord_t), 16); rdman->shnode_pool = elmpool_new(sizeof(shnode_t), 16); + rdman->sh_path_pool = elmpool_new(_sh_path_size, 16); rdman->observer_pool = elmpool_new(sizeof(observer_t), 32); rdman->subject_pool = elmpool_new(sizeof(subject_t), 32); rdman->paint_color_pool = elmpool_new(_paint_color_size, 64); @@ -720,6 +722,8 @@ elmpool_free(rdman->coord_pool); if(rdman->shnode_pool) elmpool_free(rdman->shnode_pool); + if(rdman->sh_path_pool) + elmpool_free(rdman->sh_path_pool); if(rdman->observer_pool) elmpool_free(rdman->observer_pool); if(rdman->subject_pool) @@ -779,6 +783,7 @@ elmpool_free(rdman->coord_pool); elmpool_free(rdman->geo_pool); elmpool_free(rdman->shnode_pool); + elmpool_free(rdman->sh_path_pool); elmpool_free(rdman->observer_pool); elmpool_free(rdman->subject_pool); elmpool_free(rdman->paint_color_pool);
--- a/src/shape_path.c Wed Sep 22 21:14:06 2010 +0800 +++ b/src/shape_path.c Thu Sep 23 09:55:37 2010 +0800 @@ -25,9 +25,13 @@ int float_arg_len; char *user_data; char *dev_data; /* device space data */ + + redraw_man_t *rdman; /*!< \brief This is used by sh_path_free() */ } sh_path_t; #define RESERVED_AIXS sizeof(co_aix[2]) +int _sh_path_size = sizeof(sh_path_t); + #define ASSERT(x) #define SKIP_SPACE(x) while(*(x) && (isspace(*(x)) || *(x) == ',')) { (x)++; } #define SKIP_NUM(x) \ @@ -47,6 +51,20 @@ #ifdef UNITTEST #undef rdman_shape_man #define rdman_shape_man(x, y) + +#undef elmpool_elm_alloc +#define elmpool_elm_alloc(pool) _elmpool_elm_alloc(pool) +static void * +_elmpool_elm_alloc(void *dummy) { + return malloc(sizeof(sh_path_t)); +} + +#undef elmpool_elm_free +#define elmpool_elm_free(pool, elm) _elmpool_elm_free(pool, elm) +static void +_elmpool_elm_free(void *pool, void *elm) { + free(elm); +} #endif /* ============================================================ @@ -382,7 +400,7 @@ mb_obj_destroy(path); if(path->user_data) free(path->user_data); - free(path); + elmpool_elm_free(path->rdman->sh_path_pool, path); } /*! \brief Count number of arguments. @@ -800,7 +818,7 @@ cmd_cnt = (cmd_cnt + 3) & ~0x3; /*! \todo Use elmpool to manage sh_path_t objects. */ - path = (sh_path_t *)malloc(sizeof(sh_path_t)); + path = (sh_path_t *)elmpool_elm_alloc(rdman->sh_path_pool); /*! \todo Remove this memset()? */ memset(&path->shape, 0, sizeof(shape_t)); mb_obj_init(path, MBO_PATH); @@ -812,7 +830,7 @@ sizeof(co_aix) * float_arg_cnt; path->user_data = (char *)malloc(msz * 2); if(path->user_data == NULL) { - free(path); + elmpool_elm_free(rdman->sh_path_pool, path); return NULL; } @@ -821,12 +839,13 @@ r = sh_path_cmd_arg_fill(data, path); if(r == ERR) { free(path->user_data); - free(path); + elmpool_elm_free(rdman->sh_path_pool, path); return NULL; } memcpy(path->dev_data, path->user_data, msz); path->shape.free = sh_path_free; + path->rdman = rdman; rdman_shape_man(rdman, (shape_t *)path); @@ -843,7 +862,7 @@ int cmd_cnt = strlen(commands); /*! \todo Use elmpool to manage sh_path_t objects. */ - path = (sh_path_t *)malloc(sizeof(sh_path_t)); + path = (sh_path_t *)elmpool_elm_alloc(rdman->sh_path_pool); /*! \todo Remove this memset()? */ memset(&path->shape, 0, sizeof(shape_t)); mb_obj_init(path, MBO_PATH); @@ -855,7 +874,7 @@ sizeof(co_aix) * float_arg_cnt; path->user_data = (char *)malloc(msz * 2); if(path->user_data == NULL) { - free(path); + elmpool_elm_free(rdman->sh_path_pool, path); return NULL; } @@ -867,6 +886,7 @@ memcpy(path->dev_data, path->user_data, msz); path->shape.free = sh_path_free; + path->rdman = rdman; rdman_shape_man(rdman, (shape_t *)path); @@ -1003,8 +1023,9 @@ void test_rdman_shape_path_new(void) { sh_path_t *path; co_aix *pnts; + redraw_man_t rdman; - path = (sh_path_t *)rdman_shape_path_new(NULL, "M 33 25l33 55c 33 87 44 22 55 99L33 77z"); + path = (sh_path_t *)rdman_shape_path_new(&rdman, "M 33 25l33 55c 33 87 44 22 55 99L33 77z"); CU_ASSERT(path != NULL); CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); CU_ASSERT(path->pnt_len == 12); @@ -1032,8 +1053,9 @@ co_aix *pnts; coord_t coord; geo_t geo; + redraw_man_t rdman; - path = (sh_path_t *)rdman_shape_path_new(NULL, "M 33 25l33 55C 33 87 44 22 55 99L33 77z"); + path = (sh_path_t *)rdman_shape_path_new(&rdman, "M 33 25l33 55C 33 87 44 22 55 99L33 77z"); CU_ASSERT(path != NULL); CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); CU_ASSERT(path->pnt_len == 12); @@ -1072,9 +1094,10 @@ void test_spaces_head_tail(void) { sh_path_t *path; + redraw_man_t rdman; path = (sh_path_t *) - rdman_shape_path_new(NULL, + rdman_shape_path_new(&rdman, " M 33 25l33 55C 33 87 44 22 55 99L33 77z "); CU_ASSERT(path != NULL); sh_path_free((shape_t *)path);