From: Matthew Fernandez Date: Sun, 28 Aug 2022 19:25:23 +0000 (-0700) Subject: sfdpgen beautify_leaves: swap a boolean array for a bit array X-Git-Tag: 6.0.1~14^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a2ddc51101d4f52f204b674d88d791069785e70;p=graphviz sfdpgen beautify_leaves: swap a boolean array for a bit array 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. --- diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index 7da39faf9..a692e6550 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -9,7 +9,7 @@ *************************************************************************/ #include "config.h" - +#include #include #include #include @@ -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); }