]> granicus.if.org Git - graphviz/commitdiff
get_mq: abbreviate a malloc;memzero
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 16 Sep 2021 04:11:46 +0000 (21:11 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 19 Sep 2021 04:29:41 +0000 (21:29 -0700)
The calloc function can do this more concisely and efficiently.

lib/sparse/mq.c

index 0826c7a9831707bb6d813e1803b9f1aa0e4a8274..2b57b5d497c254232464cd7947417a2b71a7b01d 100644 (file)
@@ -83,9 +83,7 @@ static real get_mq(SparseMatrix A, int *assignment, int *ncluster0, real *mq_in0
   assert(A->n == n);
   if (A->type == MATRIX_TYPE_REAL) a = (real*) A->a;
 
-  counts = MALLOC(sizeof(int)*n);
-
-  for (i = 0; i < n; i++) counts[i] = 0;
+  counts = CALLOC(n, sizeof(int));
 
   for (i = 0; i < n; i++){
     assert(assignment[i] >= 0 && assignment[i] < n);