]> granicus.if.org Git - graphviz/commitdiff
sfdpgen beautify_leaves: swap a boolean array for a bit array
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 28 Aug 2022 19:25:23 +0000 (12:25 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 31 Aug 2022 00:11:33 +0000 (17:11 -0700)
This reduces memory pressure by using 1-bit per element instead of 1-byte per
element. Unfortunately this introduces 4 -Wsign-conversion warnings due to
indexing in this function being done with signed variables. But the change still
seems like an improvement on the existing code.

lib/sfdpgen/spring_electrical.c

index 7da39faf918844d029dbb775bbff53e4ce9e09d6..a692e6550959704d07591a747e73dee7d6404f31 100644 (file)
@@ -9,7 +9,7 @@
  *************************************************************************/
 
 #include "config.h"
-
+#include <cgraph/bitarray.h>
 #include <sparse/SparseMatrix.h>
 #include <sfdpgen/spring_electrical.h>
 #include <sparse/QuadTree.h>
@@ -380,21 +380,21 @@ static void beautify_leaves(int dim, SparseMatrix A, double *x){
 
   assert(!SparseMatrix_has_diagonal(A));
 
-  bool *checked = gcalloc(sizeof(bool), m);
+  bitarray_t checked = bitarray_new_or_exit(m);
   angles = MALLOC(sizeof(double)*nangles_max);
   leaves = MALLOC(sizeof(int)*nleaves_max);
 
 
   for (i = 0; i < m; i++){
     if (ia[i+1] - ia[i] != 1) continue;
-    if (checked[i]) continue;
+    if (bitarray_get(checked, i)) continue;
     p = ja[ia[i]];
-    if (!checked[p]){
-      checked[p] = true;
+    if (!bitarray_get(checked, p)) {
+      bitarray_set(&checked, p, true);
       dist = 0; nleaves = 0; nangles = 0;
       for (j = ia[p]; j < ia[p+1]; j++){
        if (node_degree(ja[j]) == 1){
-         checked[ja[j]] = TRUE;
+         bitarray_set(&checked, ja[j], true);
          check_int_array_size(&leaves, nleaves, &nleaves_max);
          dist += distance(x, dim, p, ja[j]);
          leaves[nleaves] = ja[j];
@@ -437,8 +437,7 @@ ang1 = 0; ang2 = 2*PI; maxang = 2*PI;
     }
   }
 
-
-  free(checked);
+  bitarray_reset(&checked);
   free(angles);
   free(leaves);
 }