From: terencehill Date: Fri, 17 Mar 2023 22:08:19 +0000 (+0100) Subject: Make work IL_POP (pop from tail) and IL_SHIFT (pop from head) too during a loop ... X-Git-Tag: xonotic-v0.8.6~141^2~4 X-Git-Url: http://git.xonotic.org/?a=commitdiff_plain;ds=sidebyside;h=c6b0387ded8840abe48e8a3f4af8496d5d6f9ba1;p=xonotic%2Fxonotic-data.pk3dir.git Make work IL_POP (pop from tail) and IL_SHIFT (pop from head) too during a loop (these functions are currently never used). Also make sure il_prev and il_next fields of popped elements are consistently cleared --- diff --git a/qcsrc/lib/intrusivelist.qh b/qcsrc/lib/intrusivelist.qh index c328a6032..eabce8e71 100644 --- a/qcsrc/lib/intrusivelist.qh +++ b/qcsrc/lib/intrusivelist.qh @@ -27,7 +27,7 @@ CLASS(IntrusiveList, Object) ATTRIB(IntrusiveList, il_tail, entity); ATTRIB(IntrusiveList, il_nextfld, .entity, nil); ATTRIB(IntrusiveList, il_prevfld, .entity, nil); - ATTRIB(IntrusiveList, il_loop_item, entity, nil); + ATTRIB(IntrusiveList, il_loop_item, entity, NULL); INIT(IntrusiveList) { IL_INIT(this); } DESTRUCTOR(IntrusiveList) { IL_DTOR(this); } ENDCLASS(IntrusiveList) @@ -105,6 +105,9 @@ entity IL_POP(IntrusiveList this) entity prev = it.(il_prev); if (prev) (this.il_tail = prev).(il_next) = NULL; else this.il_head = this.il_tail = NULL; + if (this.il_loop_item == it) + this.il_loop_item = NULL; + it.(il_prev) = NULL; return it; } @@ -123,6 +126,9 @@ entity IL_SHIFT(IntrusiveList this) entity next = it.(il_next); if (next) (this.il_head = next).(il_prev) = NULL; else this.il_head = this.il_tail = NULL; + if (this.il_loop_item == it) + this.il_loop_item = it.(il_next); + it.(il_next) = NULL; return it; } @@ -192,7 +198,7 @@ void IL_REMOVE(IntrusiveList this, entity it) else \ _next = it.(il_next); /* in case next item has changed */ \ } \ - this.il_loop_item = nil; \ + this.il_loop_item = NULL; \ MACRO_END .int il_id;