]> granicus.if.org Git - graphviz/commitdiff
neatogen mkTriGraph: use cgraph wrapper for allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 18 Nov 2022 01:14:41 +0000 (17:14 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 19 Nov 2022 05:29:08 +0000 (21:29 -0800)
The lib/cgraph/alloc.h wrappers are similar to the older lib/common/memory.h
wrappers except (1) they are header-only and (2) they live in a directory
(cgraph) that is at the root of the dependency tree. The long term plan is to
replace all use of lib/common/memory.h with lib/cgraph/alloc.h.

Note that in this change we can drop some explicit initialization because the
cgraph wrappers zero-initialize.

lib/neatogen/multispline.c

index 6cc3a41ac59d7764c23f49acbb619056c50bc88d..d3ba4bee33feafed324941ffe242a615bb12c82f 100644 (file)
@@ -565,7 +565,6 @@ static void freeTriGraph(tgraph * tg)
  */
 static tgraph *mkTriGraph(surface_t * sf, int maxv, pointf * pts)
 {
-    tgraph *g;
     tnode *np;
     int j, i, ne = 0;
     int *jp;
@@ -575,28 +574,16 @@ static tgraph *mkTriGraph(surface_t * sf, int maxv, pointf * pts)
        if (sf->neigh[i] != -1)
            ne++;
 
-    g = GNEW(tgraph);
+    tgraph *g = gv_alloc(sizeof(tgraph));
 
     /* plus 2 for nodes added as endpoints of an edge */
     g->nnodes = sf->nfaces + 2;
-    g->nodes = N_GNEW(g->nnodes, tnode);
-
-    g->edges = NULL;
-    g->nedges = 0;
+    g->nodes = gv_calloc(g->nnodes, sizeof(tnode));
 
     for (i = 0; i < sf->nfaces; i++) {
        np = g->nodes + i;
-       np->ne = 0;
-       np->edges = NULL;
        np->ctr = triCenter(pts, sf->faces + 3 * i);
     }
-    /* initialize variable nodes */
-    np = g->nodes + i;
-    np->ne = 0;
-    np->edges = NULL;
-    np++;
-    np->ne = 0;
-    np->edges = NULL;
 
     for (i = 0; i < sf->nfaces; i++) {
        np = g->nodes + i;