]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
LinkedList: always update tail
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 28 Oct 2015 01:49:26 +0000 (12:49 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 28 Oct 2015 01:49:26 +0000 (12:49 +1100)
qcsrc/lib/linkedlist.qh

index 8311becb49c4fd36e3559ff748f8e4184a9968d2..2d07527c87169fb7fd3422fb922f48c9eb68fbdf 100644 (file)
@@ -21,10 +21,8 @@ entity LL_PUSH(LinkedList this, entity e)
 {
        LinkedListNode n = NEW(LinkedListNode);
        n.ll_data = e;
-       n.ll_prev = this.ll_tail;
-       LinkedListNode tail = this.ll_tail;
-       if (tail) tail.ll_next = n;
-       else this.ll_head = this.ll_tail = n;
+       LinkedListNode tail = n.ll_prev = this.ll_tail;
+       this.ll_tail = (tail) ? tail.ll_next = n : this.ll_head = n;
        return e;
 }
 
@@ -43,15 +41,15 @@ entity LL_POP(LinkedList this)
 }
 
 #define LL_EACH(list, cond, body) \
-       do \
-       {                                  \
-               noref int i = 0;                                                    \
-               for (entity _it = list.ll_head; _it; (_it = _it.ll_next, ++i)) \
-               {    \
-                       noref entity it = _it.ll_data;                                  \
-                       if (cond) { body }                                              \
-               }                                                                   \
-       } \
+       do                                                                  \
+       {                                                                   \
+               noref int i = 0;                                                \
+               for (entity _it = list.ll_head; _it; (_it = _it.ll_next, ++i))  \
+               {                                                               \
+                       noref entity it = _it.ll_data;                              \
+                       if (cond) { body }                                          \
+               }                                                               \
+       }                                                                   \
        while (0)
 
 #endif