From: Matthew Fernandez Date: Wed, 14 Sep 2022 01:17:29 +0000 (-0700) Subject: dotgen: use a bit array for 'layerWidthInfo_t.removed' X-Git-Tag: 6.0.2~38^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32ebb7935acd69884b800e923fd49800d4b6f004;p=graphviz dotgen: use a bit array for 'layerWidthInfo_t.removed' By using a `bitarray_t` instead of an array of integers for this array of boolean values, we swap a 32-bits-per-boolean representation for a 1-bit-per-boolean representation. This reduces heap pressure, and in the case of smaller arrays avoids heap allocation altogether. --- diff --git a/lib/dotgen/aspect.c b/lib/dotgen/aspect.c index 46536cab6..9d09e30f1 100644 --- a/lib/dotgen/aspect.c +++ b/lib/dotgen/aspect.c @@ -8,7 +8,10 @@ * Contributors: Details at https://graphviz.org *************************************************************************/ +#include +#include #include +#include /* * Author: Mohammad T. Irfan @@ -151,7 +154,7 @@ int countDummyNodes(graph_t * g) typedef struct layerWidthInfo_t { int layerNumber; nodeGroup_t **nodeGroupsInLayer; - int *removed; /* is the node group removed? */ + bitarray_t removed; // is the node group removed? int nNodeGroupsInLayer; int nDummyNodes; double width; @@ -184,7 +187,7 @@ static void computeLayerWidths(graph_t * g) } free(layerWidthInfo[i].nodeGroupsInLayer); } - free(layerWidthInfo[i].removed); + bitarray_reset(&layerWidthInfo[i].removed); } free(layerWidthInfo); @@ -198,7 +201,8 @@ static void computeLayerWidths(graph_t * g) layerWidthInfo[i].nodeGroupsInLayer = N_NEW(nNodeGroups, nodeGroup_t *); - layerWidthInfo[i].removed = N_NEW(nNodeGroups, int); + assert(nNodeGroups >= 0); + layerWidthInfo[i].removed = bitarray_new_or_exit((size_t)nNodeGroups); layerWidthInfo[i].layerNumber = i; layerWidthInfo[i].nNodeGroupsInLayer = 0; @@ -368,7 +372,7 @@ static void reduceMaxWidth2(graph_t * g) w = 0; for (i = 0; i < limit + rem; i++) { - if (layerWidthInfo[maxLayerIndex].removed[i]) { + if (bitarray_get(layerWidthInfo[maxLayerIndex].removed, i)) { rem++; continue; } @@ -409,7 +413,7 @@ static void reduceMaxWidth2(graph_t * g) /* the following code updates the layer width information. The * update is not useful in the current version of the heuristic. */ - layerWidthInfo[maxLayerIndex].removed[i] = 1; + bitarray_set(&layerWidthInfo[maxLayerIndex].removed, i, true); rem2++; layerWidthInfo[maxLayerIndex].nNodeGroupsInLayer--; /* SHOULD BE INCREASED BY THE SUM OF INDEG OF ALL NODES IN GROUP */