From: Matthew Fernandez Date: Sun, 6 Feb 2022 06:51:16 +0000 (+1100) Subject: netogen: [nfc] rewrite 'push' and 'pop' macros as functions X-Git-Tag: 3.0.0~39^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd989d3f4f7e3f0c5425071c5116024fc2c0e7a0;p=graphviz netogen: [nfc] rewrite 'push' and 'pop' macros as functions There is no need for these to be macros. Modern compilers will easily inline these helpers. Making them functions provides additional type safety. --- diff --git a/lib/neatogen/closest.c b/lib/neatogen/closest.c index 3ca9a01a0..bc6c99159 100644 --- a/lib/neatogen/closest.c +++ b/lib/neatogen/closest.c @@ -49,15 +49,21 @@ static void freeStack(PairStack * s) free(s->data); } -#define push(s,x) { \ - if (s->top>=s->max_size) { \ - s->max_size *= 2; \ - s->data = realloc(s->data, s->max_size*sizeof(Pair)); \ - } \ - s->data[s->top++] = x; \ +static void push(PairStack *s, Pair x) { + if (s->top >= s->max_size) { + s->max_size *= 2; + s->data = realloc(s->data, s->max_size * sizeof(Pair)); + } + s->data[s->top++] = x; } -#define pop(s,x) ((s->top==0) ? FALSE : (s->top--, x = s->data[s->top], TRUE)) +static bool pop(PairStack *s, Pair *x) { + if (s->top == 0) + return false; + --s->top; + *x = s->data[s->top]; + return true; +} #define sub(h,i) (h->data[i]) @@ -307,7 +313,7 @@ construct_graph(int n, PairStack * edges_stack, vtx_data ** New_graph) free(degrees); /* add all edges from stack */ - while (pop(edges_stack, pair)) { + while (pop(edges_stack, &pair)) { add_edge(new_graph, pair.left, pair.right); } }