Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
146:e96a584487af | 147:995ee8fd5f1a |
---|---|
194 coord->num_members--; | 194 coord->num_members--; |
195 } | 195 } |
196 | 196 |
197 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) { | 197 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) { |
198 extern void redraw_man_destroy(redraw_man_t *rdman); | 198 extern void redraw_man_destroy(redraw_man_t *rdman); |
199 extern int paint_color_size; | 199 extern int _paint_color_size; |
200 | 200 |
201 memset(rdman, 0, sizeof(redraw_man_t)); | 201 memset(rdman, 0, sizeof(redraw_man_t)); |
202 | 202 |
203 rdman->geo_pool = elmpool_new(sizeof(geo_t), 128); | 203 rdman->geo_pool = elmpool_new(sizeof(geo_t), 128); |
204 if(rdman->geo_pool == NULL) | 204 if(rdman->geo_pool == NULL) |
232 elmpool_free(rdman->shnode_pool); | 232 elmpool_free(rdman->shnode_pool); |
233 elmpool_free(rdman->observer_pool); | 233 elmpool_free(rdman->observer_pool); |
234 return ERR; | 234 return ERR; |
235 } | 235 } |
236 | 236 |
237 rdman->paint_color_pool = elmpool_new(paint_color_size, 64); | 237 rdman->paint_color_pool = elmpool_new(_paint_color_size, 64); |
238 if(rdman->subject_pool == NULL) { | 238 if(rdman->subject_pool == NULL) { |
239 elmpool_free(rdman->geo_pool); | 239 elmpool_free(rdman->geo_pool); |
240 elmpool_free(rdman->coord_pool); | 240 elmpool_free(rdman->coord_pool); |
241 elmpool_free(rdman->shnode_pool); | 241 elmpool_free(rdman->shnode_pool); |
242 elmpool_free(rdman->observer_pool); | 242 elmpool_free(rdman->observer_pool); |
563 } | 563 } |
564 coord->canvas = coord->parent->canvas; | 564 coord->canvas = coord->parent->canvas; |
565 } | 565 } |
566 } | 566 } |
567 | 567 |
568 /*! \todo Use a static variable to hold positions array for clean_coord()? */ | |
569 static int clean_coord(redraw_man_t *rdman, coord_t *coord) { | 568 static int clean_coord(redraw_man_t *rdman, coord_t *coord) { |
570 geo_t *geo; | 569 geo_t *geo; |
571 co_aix (*poses)[2]; | 570 /*! \note poses is shared by invokings, it is not support reentrying. */ |
571 static co_aix (*poses)[2]; | |
572 static int max_poses = 0; | |
572 int cnt, pos_cnt; | 573 int cnt, pos_cnt; |
573 | 574 |
574 setup_canvas(rdman, coord); | 575 setup_canvas(rdman, coord); |
575 | 576 |
576 compute_aggr_of_coord(coord); | 577 compute_aggr_of_coord(coord); |
582 clean_shape(geo->shape); | 583 clean_shape(geo->shape); |
583 cnt++; | 584 cnt++; |
584 } | 585 } |
585 | 586 |
586 /* Compute area of the coord. */ | 587 /* Compute area of the coord. */ |
587 poses = (co_aix (*)[2])malloc(sizeof(co_aix [2]) * 2 * cnt); | 588 if(max_poses < (cnt * 2)) { |
588 if(poses == NULL) | 589 free(poses); |
589 return ERR; | 590 max_poses = cnt * 2; |
591 poses = (co_aix (*)[2])malloc(sizeof(co_aix [2]) * max_poses); | |
592 if(poses == NULL) | |
593 return ERR; | |
594 } | |
590 | 595 |
591 pos_cnt = 0; | 596 pos_cnt = 0; |
592 FORMEMBERS(coord, geo) { | 597 FORMEMBERS(coord, geo) { |
593 area_to_positions(geo->cur_area, poses + pos_cnt); | 598 area_to_positions(geo->cur_area, poses + pos_cnt); |
594 pos_cnt += 2; | 599 pos_cnt += 2; |
595 } | 600 } |
596 | 601 |
597 SWAP(coord->cur_area, coord->last_area, area_t *); | 602 SWAP(coord->cur_area, coord->last_area, area_t *); |
598 area_init(coord->cur_area, pos_cnt, poses); | 603 area_init(coord->cur_area, pos_cnt, poses); |
599 free(poses); | |
600 | 604 |
601 coord->flags &= ~COF_DIRTY; | 605 coord->flags &= ~COF_DIRTY; |
602 | 606 |
603 return OK; | 607 return OK; |
604 } | 608 } |