From 2c2c6512bd90d0946077fb61911fa6021c5f0cf1 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 5 Dec 2015 21:49:57 +1100 Subject: [PATCH] LinkedList: rebase delete method on clear --- qcsrc/lib/linkedlist.qh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/qcsrc/lib/linkedlist.qh b/qcsrc/lib/linkedlist.qh index b2aabd229..3f57fdbc7 100644 --- a/qcsrc/lib/linkedlist.qh +++ b/qcsrc/lib/linkedlist.qh @@ -45,9 +45,9 @@ entity LL_POP(LinkedList this) return e; } -#define LL_DELETE(...) EVAL(OVERLOAD(LL_DELETE, __VA_ARGS__)) -#define LL_DELETE_1(this) LL_DELETE_2(this, LAMBDA()) -#define LL_DELETE_2(this, dtor) \ +#define LL_CLEAR(...) EVAL(OVERLOAD(LL_CLEAR, __VA_ARGS__)) +#define LL_CLEAR_1(this) LL_CLEAR_2(this, LAMBDA()) +#define LL_CLEAR_2(this, dtor) \ do \ { \ LinkedList _ll = this; \ @@ -59,7 +59,16 @@ entity LL_POP(LinkedList this) dtor \ remove(it); \ } \ - remove(_ll); \ + } \ + while (0) + +#define LL_DELETE(...) EVAL(OVERLOAD(LL_DELETE, __VA_ARGS__)) +#define LL_DELETE_1(this) LL_DELETE_2(this, LAMBDA()) +#define LL_DELETE_2(this, dtor) \ + do \ + { \ + LL_CLEAR(this, dtor); \ + remove(this); \ this = NULL; \ } \ while (0) -- 2.39.2