MT#55283 use helper struct instead of void* array

Change-Id: Ic9992d3206d39a9f0274c8d88a3a027b26ba751f
pull/1802/head
Richard Fuchs 1 year ago
parent 96a894ff8b
commit 2160cb0fbf

@ -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;
}

@ -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);

Loading…
Cancel
Save