From: Matthew Fernandez Date: Sun, 19 Dec 2021 19:46:01 +0000 (-0800) Subject: dijkstra_bounded: remove an allocator optimization X-Git-Tag: 3.0.0~120^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=01483ed844cf7acb29914e45dfd07299861fbf99;p=graphviz dijkstra_bounded: remove an allocator optimization Similar to the prior commit, the previous code was actually a _deoptimization_. --- diff --git a/lib/neatogen/dijkstra.c b/lib/neatogen/dijkstra.c index 2c5011b07..d55f7eb22 100644 --- a/lib/neatogen/dijkstra.c +++ b/lib/neatogen/dijkstra.c @@ -186,7 +186,6 @@ dijkstra_bounded(int vertex, vtx_data * graph, int n, DistType * dist, int i; static boolean *node_in_neighborhood = NULL; static int size = 0; - static int *index; Queue Q; heap H; int closestVertex, neighbor; @@ -212,8 +211,7 @@ dijkstra_bounded(int vertex, vtx_data * graph, int n, DistType * dist, node_in_neighborhood[visited_nodes[i]] = TRUE; } - - index = realloc(index, n * sizeof(int)); + int *index = gcalloc(n, sizeof(int)); /* initial distances with edge weights: */ for (i = 0; i < n; i++) /* far, TOO COSTLY (O(n))! */ @@ -247,6 +245,7 @@ dijkstra_bounded(int vertex, vtx_data * graph, int n, DistType * dist, node_in_neighborhood[visited_nodes[i]] = FALSE; } freeHeap(&H); + free(index); freeQueue(&Q); return num_visited_nodes; }