]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: list: add LIST_SPLICE() to merge one list into another
authorWilly Tarreau <w@1wt.eu>
Fri, 16 Aug 2019 09:27:50 +0000 (11:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Aug 2019 18:21:00 +0000 (20:21 +0200)
This will move the contents of list <old> at the beginning of list
<new>.

include/common/mini-clist.h

index 592bb9613666e991876e449a4a9b82b78bb7e314..0cdddce04f79b9ca4c191e5e232233b23b024027 100644 (file)
@@ -86,6 +86,14 @@ struct cond_wordlist {
 /* adds an element at the end of a list ; returns the element */
 #define LIST_ADDQ(lh, el) ({ (el)->p = (lh)->p; (el)->p->n = (lh)->p = (el); (el)->n = (lh); (el); })
 
+/* adds the contents of a list <old> at the beginning of another list <new>. The old list head remains untouched. */
+#define LIST_SPLICE(new, old) do {                                  \
+               if (!LIST_ISEMPTY(old)) {                            \
+                       (old)->p->n = (new)->n; (old)->n->p = (new); \
+                       (new)->n->p = (old)->p; (new)->n = (old)->n; \
+               }                                                    \
+       } while (0)
+
 /* removes an element from a list and returns it */
 #define LIST_DEL(el) ({ typeof(el) __ret = (el); (el)->n->p = (el)->p; (el)->p->n = (el)->n; (__ret); })