]> granicus.if.org Git - graphviz/commitdiff
sfdpgen spring_electrical_embedding_slow: use cgraph wrappers for allocation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 10 Sep 2022 03:39:50 +0000 (20:39 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 11 Sep 2022 23:56:02 +0000 (16:56 -0700)
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.

lib/sfdpgen/spring_electrical.c

index 2f19b3d3bab2a3aa28a5a2e2b67b8fd4c4d731d6..b9f8875fffe05ef7a9b8a479bb4590f4b8279078 100644 (file)
@@ -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;