diff --git a/lib/auxlib.c b/lib/auxlib.c index 21bfb5764..ad706fe9f 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -451,20 +451,17 @@ int timeval_cmp_ptr(const void *a, const void *b) { } int rtpe_tree_find_first_cmp(void *k, void *v, void *d) { - void **p = d; - GEqualFunc f = p[1]; - if (!f || f(v, p[0])) { - p[2] = v; + struct rtpe_g_tree_find_helper *h = d; + if (!h->func || h->func(v, h->data)) { + h->out_p = v; return TRUE; } return FALSE; } int rtpe_tree_find_all_cmp(void *k, void *v, void *d) { - void **p = d; - GEqualFunc f = p[1]; - GQueue *q = p[2]; - if (!f || f(v, p[0])) - g_queue_push_tail(q, v); + struct rtpe_g_tree_find_helper *h = d; + if (!h->func || h->func(v, h->data)) + g_queue_push_tail(h->out_q, v); return FALSE; } diff --git a/lib/auxlib.h b/lib/auxlib.h index dff9b73aa..4baca948b 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -359,20 +359,31 @@ INLINE void g_tree_clear(GTree *t) { int rtpe_tree_find_first_cmp(void *, void *, void *); int rtpe_tree_find_all_cmp(void *, void *, void *); + +struct rtpe_g_tree_find_helper { + GEqualFunc func; + void *data; + union { + GQueue *out_q; + void *out_p; + }; +}; + INLINE void *g_tree_find_first(GTree *t, GEqualFunc f, void *data) { - void *p[3]; - p[0] = data; - p[1] = f; - p[2] = NULL; - g_tree_foreach(t, rtpe_tree_find_first_cmp, p); - return p[2]; + struct rtpe_g_tree_find_helper h = { + .func = f, + .data = data, + }; + g_tree_foreach(t, rtpe_tree_find_first_cmp, &h); + return h.out_p; } INLINE void g_tree_find_all(GQueue *out, GTree *t, GEqualFunc f, void *data) { - void *p[3]; - p[0] = data; - p[1] = f; - p[2] = out; - g_tree_foreach(t, rtpe_tree_find_all_cmp, p); + struct rtpe_g_tree_find_helper h = { + .func = f, + .data = data, + .out_q = out, + }; + g_tree_foreach(t, rtpe_tree_find_all_cmp, &h); } INLINE void g_tree_get_values(GQueue *out, GTree *t) { g_tree_find_all(out, t, NULL, NULL);