From 03fd8e1c4e0b59c57b0739d8da20d97f1dbfb6de Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 27 Apr 2023 12:08:44 -0400 Subject: [PATCH] MT#57268 improve g_queue_move() No need to iterate the list to achieve what the function does. We can simply adjust pointers and count. Change-Id: I849817e53d859ac73c14131b54a6d05e4efeb37e --- include/aux.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/aux.h b/include/aux.h index d4f4244b6..32b40b492 100644 --- a/include/aux.h +++ b/include/aux.h @@ -153,10 +153,19 @@ INLINE char *glib_json_print(JsonBuilder *builder) { /* GQUEUE */ +// appends `src` to the end of `dst` and clears out `src` INLINE void g_queue_move(GQueue *dst, GQueue *src) { - GList *l; - while ((l = g_queue_pop_head_link(src))) - g_queue_push_tail_link(dst, l); + if (!src->length) + return; + if (!dst->length) { + *dst = *src; + g_queue_init(src); + return; + } + dst->tail->next = src->head; + src->head->prev = dst->tail; + dst->length += src->length; + g_queue_init(src); } INLINE void g_queue_truncate(GQueue *q, unsigned int len) { while (q->length > len)