Index: trunk/src/main.c =================================================================== --- trunk/src/main.c (revision 25543) +++ trunk/src/main.c (revision 25544) @@ -286,6 +286,8 @@ } } +extern void pcb_poly_uninit(void); + void pcb_main_uninit(void) { if (pcb_log_last != NULL) @@ -328,6 +330,7 @@ pcb_fp_uninit(); pcb_fp_host_uninit(); pcb_tool_uninit(); + pcb_poly_uninit(); log_print_uninit_errs("Log produced during uninitialization"); pcb_log_uninit(); Index: trunk/src/obj_poly.c =================================================================== --- trunk/src/obj_poly.c (revision 25543) +++ trunk/src/obj_poly.c (revision 25544) @@ -1329,3 +1329,8 @@ { pcb_draw_invalidate(Polygon); } + +void pcb_poly_uninit(void) +{ + pcb_dhlp_uninit(); +} Index: trunk/src/obj_poly.h =================================================================== --- trunk/src/obj_poly.h (revision 25543) +++ trunk/src/obj_poly.h (revision 25544) @@ -95,6 +95,10 @@ double pcb_poly_area(const pcb_poly_t *poly); +/* called from main.c to free some caches */ +void pcb_poly_uninit(void); + + /*** helpers for iterating over countours */ /*** Polygon helpers on the clopped polygon ***/ Index: trunk/src/obj_poly_draw_helper.c =================================================================== --- trunk/src/obj_poly_draw_helper.c (revision 25543) +++ trunk/src/obj_poly_draw_helper.c (revision 25544) @@ -34,24 +34,30 @@ #include "obj_poly.h" #include "hid_inlines.h" +static pcb_coord_t *fc_x = NULL, *fc_y = NULL; +static size_t fc_alloced = 0; + static void fill_contour(pcb_hid_gc_t gc, pcb_pline_t * pl) { - pcb_coord_t *x, *y, n, i = 0; + size_t n, i = 0; pcb_vnode_t *v; n = pl->Count; - x = (pcb_coord_t *) malloc(n * sizeof(*x)); - y = (pcb_coord_t *) malloc(n * sizeof(*y)); + if (n > fc_alloced) { + free(fc_x); + free(fc_y); + fc_x = (pcb_coord_t *) malloc(n * sizeof(pcb_coord_t)); + fc_y = (pcb_coord_t *) malloc(n * sizeof(pcb_coord_t)); + fc_alloced = n; + } + for (v = &pl->head; i < n; v = v->next) { - x[i] = v->point[0]; - y[i++] = v->point[1]; + fc_x[i] = v->point[0]; + fc_y[i++] = v->point[1]; } - pcb_gui->fill_polygon(gc, n, x, y); - - free(x); - free(y); + pcb_gui->fill_polygon(gc, n, fc_x, fc_y); } static void thindraw_contour(pcb_hid_gc_t gc, pcb_pline_t * pl) @@ -221,3 +227,11 @@ thindraw_contour(gc, poly->Clipped->contours); pcb_poly_holes(poly, clip_box, thindraw_hole_cb, gc); } + +static void pcb_dhlp_uninit(void) +{ + free(fc_x); + free(fc_y); + fc_x = fc_y = NULL; + fc_alloced= 0; +}