Index: trunk/src/obj_poly.c =================================================================== --- trunk/src/obj_poly.c (revision 34548) +++ trunk/src/obj_poly.c (revision 34549) @@ -122,22 +122,32 @@ free(poly); } -/* gets the next slot for a point in a polygon struct, allocates memory if necessary */ -rnd_point_t *pcb_poly_point_alloc(pcb_poly_t *Polygon) +/* realloc new memory if necessary and clear it */ +RND_INLINE void pcb_poly_point_prealloc_(pcb_poly_t *Polygon, long num_pt, long step) { - rnd_point_t *points = Polygon->Points; + if (num_pt >= Polygon->PointMax) { + long diff, old = Polygon->PointMax; - /* realloc new memory if necessary and clear it */ - if (Polygon->PointN >= Polygon->PointMax) { - Polygon->PointMax += STEP_POLYGONPOINT; - points = (rnd_point_t *) realloc(points, Polygon->PointMax * sizeof(rnd_point_t)); - Polygon->Points = points; - memset(points + Polygon->PointN, 0, STEP_POLYGONPOINT * sizeof(rnd_point_t)); + Polygon->PointMax = num_pt + step; + diff = Polygon->PointMax - old; + Polygon->Points = realloc(Polygon->Points, Polygon->PointMax * sizeof(rnd_point_t)); + memset(Polygon->Points + old, 0, diff * sizeof(rnd_point_t)); } - return (points + Polygon->PointN++); } +void pcb_poly_point_prealloc(pcb_poly_t *Polygon, long num_pt) +{ + return pcb_poly_point_prealloc_(Polygon, num_pt, 0); +} + /* gets the next slot for a point in a polygon struct, allocates memory if necessary */ +rnd_point_t *pcb_poly_point_alloc(pcb_poly_t *Polygon) +{ + pcb_poly_point_prealloc_(Polygon, Polygon->PointN, STEP_POLYGONPOINT); + return (Polygon->Points + Polygon->PointN++); +} + +/* gets the next slot for a point in a polygon struct, allocates memory if necessary */ rnd_cardinal_t *pcb_poly_holeidx_new(pcb_poly_t *Polygon) { rnd_cardinal_t *holeindex = Polygon->HoleIndex; Index: trunk/src/obj_poly.h =================================================================== --- trunk/src/obj_poly.h (revision 34548) +++ trunk/src/obj_poly.h (revision 34549) @@ -62,6 +62,10 @@ rnd_cardinal_t *pcb_poly_holeidx_new(pcb_poly_t *Polygon); void pcb_poly_free_fields(pcb_poly_t * polygon); +/* Enlarge memory allocation in one step to host num_pts */ +void pcb_poly_point_prealloc(pcb_poly_t *Polygon, long num_pt); + + void pcb_poly_reg(pcb_layer_t *layer, pcb_poly_t *poly); void pcb_poly_unreg(pcb_poly_t *poly);