From: Matthew Fernandez Date: Thu, 18 Aug 2022 01:52:13 +0000 (-0700) Subject: common point_gencode: tighter scope and stack-allocate 'AF' X-Git-Tag: 6.0.1~33^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=105ab46277c15a220afa717c3fc208a38e3b65f1;p=graphviz common point_gencode: tighter scope and stack-allocate 'AF' `AF` was being dynamically allocated as if it needed to contain an arbitrary (potentially large) number of points. However its only use is in being passed to `gvrender_ellipse` which only looks at the first two points. So we can simplify and optimize this code by simply stack-allocating 2 entries. --- diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 15f0e4bed..3854e3ca8 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -3081,8 +3081,6 @@ static void point_gencode(GVJ_t * job, node_t * n) polygon_t *poly; int i, j, sides, peripheries, style; pointf P, *vertices; - static pointf *AF; - static int A_size; bool filled; char *color; int doMap = obj->url || obj->explicit_tooltip; @@ -3096,10 +3094,6 @@ static void point_gencode(GVJ_t * job, node_t * n) vertices = poly->vertices; sides = poly->sides; peripheries = poly->peripheries; - if (A_size < sides) { - A_size = sides + 2; - AF = ALLOC(A_size, AF, pointf); - } checkStyle(n, &style); if (style & INVISIBLE) @@ -3152,10 +3146,14 @@ static void point_gencode(GVJ_t * job, node_t * n) } for (j = 0; j < peripheries; j++) { + enum {A_size = 2}; + pointf AF[A_size] = {{0}}; for (i = 0; i < sides; i++) { P = vertices[i + j * sides]; - AF[i].x = P.x + ND_coord(n).x; - AF[i].y = P.y + ND_coord(n).y; + if (i < A_size) { + AF[i].x = P.x + ND_coord(n).x; + AF[i].y = P.y + ND_coord(n).y; + } } gvrender_ellipse(job, AF, filled); /* fill innermost periphery only */