]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make work IL_POP (pop from tail) and IL_SHIFT (pop from head) too during a loop ...
authorterencehill <piuntn@gmail.com>
Fri, 17 Mar 2023 22:08:19 +0000 (23:08 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 17 Mar 2023 22:08:19 +0000 (23:08 +0100)
qcsrc/lib/intrusivelist.qh

index c328a603266590d311941ac39b60389db7211399..eabce8e71a711870f2e21d2eaac5b050f0fa7357 100644 (file)
@@ -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;