From cd989d3f4f7e3f0c5425071c5116024fc2c0e7a0 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 6 Feb 2022 17:51:16 +1100 Subject: [PATCH] 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. --- lib/neatogen/closest.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) 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); } } -- 2.40.0