]> granicus.if.org Git - graphviz/commitdiff
make_flat_bottom_edges: use a local box array instead of the global boxes
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 11 Jul 2021 23:57:14 +0000 (16:57 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 18 Jul 2021 19:59:52 +0000 (12:59 -0700)
The values written to this array during make_flat_bottom_edges do not need to be
retained after the function returns. It was simply using the boxes as scratch
space. Using a local array instead makes it easier for the compiler to optimize
and will ease some upcoming changes. Related to #2095.

This introduces a new -Wshadow compiler warning, but that will be removed in a
future commit.

lib/dotgen/dotsplines.c

index 939dc1127eb16564948fb7fdd3b9ba5abf629dc0..a1acf66b846818ef404614a6196686b40fbc0014 100644 (file)
@@ -13,6 +13,7 @@
  * set edge splines.
  */
 
+#include <assert.h>
 #include <dotgen/dot.h>
 #include <math.h>
 #include <stddef.h>
@@ -1469,10 +1470,11 @@ make_flat_bottom_edges(graph_t* g, spline_info_t* sp, path * P, edge_t ** edges,
     makeBottomFlatEnd (g, sp, P, hn, e, &hend, FALSE);
 
     for (i = 0; i < cnt; i++) {
-       int boxn;
        boxf b;
        e = edges[ind + i];
-       boxn = 0;
+       size_t boxn = 0;
+
+       boxf boxes[3];
 
        b = tend.boxes[tend.boxn - 1];
        boxes[boxn].LL.x = b.LL.x; 
@@ -1491,9 +1493,10 @@ make_flat_bottom_edges(graph_t* g, spline_info_t* sp, path * P, edge_t ** edges,
        boxes[boxn].LL.x = b.LL.x - (i + 1) * stepx;
        boxes[boxn].LL.y = boxes[boxn-1].UR.y;
        boxn++;
+       assert(boxn == sizeof(boxes) / sizeof(boxes[0]));
 
        for (j = 0; j < tend.boxn; j++) add_box(P, tend.boxes[j]);
-       for (j = 0; j < boxn; j++) add_box(P, boxes[j]);
+       for (size_t k = 0; k < boxn; k++) add_box(P, boxes[k]);
        for (j = hend.boxn - 1; j >= 0; j--) add_box(P, hend.boxes[j]);
 
        if (splines) ps = routesplines(P, &pn);