Browse Source

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
pull/1646/head
Richard Fuchs 3 years ago
parent
commit
03fd8e1c4e
1 changed files with 12 additions and 3 deletions
  1. +12
    -3
      include/aux.h

+ 12
- 3
include/aux.h View File

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


Loading…
Cancel
Save