From: Matthew Fernandez Date: Sat, 10 Sep 2022 03:39:50 +0000 (-0700) Subject: sfdpgen spring_electrical_embedding_slow: use cgraph wrappers for allocation X-Git-Tag: 6.0.2~44^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d01d6f05d48141c6bfe8a507a6b6cea1ef7acf54;p=graphviz sfdpgen spring_electrical_embedding_slow: use cgraph wrappers for allocation 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. --- diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index 2f19b3d3b..b9f8875ff 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -680,14 +680,14 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el m = A->m, n = A->n; if (n <= 0 || dim <= 0) return; - force = MALLOC(sizeof(double)*n*dim); + force = gv_calloc(n *dim, sizeof(double)); if (n >= ctrl->quadtree_size) { USE_QT = TRUE; qtree_level_optimizer = oned_optimizer_new(max_qtree_level); - center = MALLOC(sizeof(double)*nsupermax*dim); - supernode_wgts = MALLOC(sizeof(double)*nsupermax); - distances = MALLOC(sizeof(double)*nsupermax); + center = gv_calloc(nsupermax * dim, sizeof(double)); + supernode_wgts = gv_calloc(nsupermax, sizeof(double)); + distances = gv_calloc(nsupermax, sizeof(double)); } USE_QT = FALSE; *flag = 0; @@ -724,8 +724,8 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el } #endif - f = MALLOC(sizeof(double)*dim); - xold = MALLOC(sizeof(double)*dim*n); + f = gv_calloc(dim, sizeof(double)); + xold = gv_calloc(dim * n, sizeof(double)); do { for (i = 0; i < dim*n; i++) force[i] = 0;