From: TimePath Date: Wed, 28 Oct 2015 01:49:26 +0000 (+1100) Subject: LinkedList: always update tail X-Git-Tag: xonotic-v0.8.2~1775 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=46bfbe045f678b7028e9d3cd0e391967334ee478;p=xonotic%2Fxonotic-data.pk3dir.git LinkedList: always update tail --- diff --git a/qcsrc/lib/linkedlist.qh b/qcsrc/lib/linkedlist.qh index 8311becb4..2d07527c8 100644 --- a/qcsrc/lib/linkedlist.qh +++ b/qcsrc/lib/linkedlist.qh @@ -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