From: Matthew Fernandez Date: Fri, 18 Nov 2022 01:27:12 +0000 (-0800) Subject: neatogen: remove upfront allocation of trigraph edges X-Git-Tag: 7.0.3~11^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=544efc06034f4a0116e5b599474a9010c6efc570;p=graphviz neatogen: remove upfront allocation of trigraph edges Following on from fc465488e1e62fe5ef879b379a07ef272431f400, this removes assumptions about how many total edges will be generated by this algorithm. New edges are now allocated on demand when appending. --- diff --git a/lib/neatogen/multispline.c b/lib/neatogen/multispline.c index eec809fea..0da8a3eb4 100644 --- a/lib/neatogen/multispline.c +++ b/lib/neatogen/multispline.c @@ -528,6 +528,8 @@ static ipair sharedEdge(int *p, int *q) * segment seg. */ static void addTriEdge(tgraph *g, int t, int h, ipair seg) { + g->edges = gv_recalloc(g->edges, g->nedges, g->nedges + 1, + sizeof(g->edges[0])); tedge *ep = g->edges + g->nedges; tnode *tp = g->nodes + t; tnode *hp = g->nodes + h; @@ -579,10 +581,7 @@ static tgraph *mkTriGraph(surface_t * sf, int maxv, pointf * pts) g->nnodes = sf->nfaces + 2; g->nodes = N_GNEW(g->nnodes, tnode); - /* allow 1 possible extra edge per triangle, plus - * obstacles can have at most maxv triangles touching - */ - g->edges = N_GNEW(ne/2 + 2 * maxv, tedge); + g->edges = NULL; g->nedges = 0; for (i = 0; i < sf->nfaces; i++) {