From cc9d061e51fccc8527f80893c80fe085330a0029 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 21 Jul 2023 13:16:43 +0200 Subject: [PATCH] util/IntrusiveList: pop_front() and pop_back() return reference --- src/util/IntrusiveList.hxx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/util/IntrusiveList.hxx b/src/util/IntrusiveList.hxx index f8b5116e5..6e10f9797 100644 --- a/src/util/IntrusiveList.hxx +++ b/src/util/IntrusiveList.hxx @@ -264,9 +264,7 @@ public: void clear_and_dispose(Disposer auto disposer) noexcept { while (!empty()) { - auto *item = &front(); - pop_front(); - disposer(item); + disposer(&pop_front()); } } @@ -302,15 +300,15 @@ public: return *Cast(head.next); } - void pop_front() noexcept { - ToHook(front()).unlink(); - --counter; - } - - void pop_front_and_dispose(Disposer auto disposer) noexcept { + reference pop_front() noexcept { auto &i = front(); ToHook(i).unlink(); --counter; + return i; + } + + void pop_front_and_dispose(Disposer auto disposer) noexcept { + auto &i = pop_front(); disposer(&i); } @@ -319,7 +317,8 @@ public: } void pop_back() noexcept { - ToHook(back()).unlink(); + auto &i = back(); + ToHook(i).unlink(); --counter; }