]> granicus.if.org Git - graphviz/commitdiff
makeStraightEdge: remove array allocation optimization
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 13 Dec 2021 02:07:24 +0000 (18:07 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 14 Dec 2021 05:49:21 +0000 (21:49 -0800)
This code had two alternative paths, one that used a heap-allocated array for
edge counts above 20 and one that used a stack-allocated array for edge counts
of 20 or less. The latter was an optimization to avoid heap allocation for
smaller graphs. Modern dynamic allocators are fast enough that this kind of
optimization is no longer relevant.

lib/common/routespl.c

index 67b107da15fbd71014b87b5e797e973e69e18492..684ca8b6236f4027f524093fdc39bd27238179cb 100644 (file)
@@ -1092,31 +1092,24 @@ static void bend(pointf spl[4], pointf centroid)
  *
  * FIX: handle ports on boundary?
  */
-#define MAX_EDGE 20
 void 
 makeStraightEdge(graph_t * g, edge_t * e, int et, splineInfo* sinfo)
 {
     edge_t *e0;
-    edge_t** edges;
-    edge_t* elist[MAX_EDGE];
     int i, e_cnt;
 
     e_cnt = 1;
     e0 = e;
     while (e0 != ED_to_virt(e0) && (e0 = ED_to_virt(e0))) e_cnt++;
 
-    if (e_cnt <= MAX_EDGE)
-       edges = elist;
-    else
-       edges = N_NEW(e_cnt,edge_t*);
+    edge_t **edges = N_NEW(e_cnt, edge_t*);
     e0 = e;
     for (i = 0; i < e_cnt; i++) {
        edges[i] = e0;
        e0 = ED_to_virt(e0);
     }
     makeStraightEdges (g, edges, e_cnt, et, sinfo);
-    if (e_cnt > MAX_EDGE) free (edges);
-
+    free(edges);
 }
 
 void