From 66e94ac41b6e4e5d8faac1c2cd3f8a3a9890c39f Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Thu, 7 Dec 2023 00:18:33 -0800 Subject: [PATCH] [Glacier] Allow removing from an intrusive list. --- lib/glacier/container/intrusive_list.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/glacier/container/intrusive_list.h b/lib/glacier/container/intrusive_list.h index 8957a32..aef7b83 100644 --- a/lib/glacier/container/intrusive_list.h +++ b/lib/glacier/container/intrusive_list.h @@ -20,6 +20,8 @@ class IntrusiveList { void PushFront(const RefPtr& obj); void PushBack(const RefPtr& obj); + void Remove(const RefPtr& obj); + RefPtr PopFront(); RefPtr PopBack(); @@ -64,6 +66,29 @@ void IntrusiveList::PushBack(const RefPtr& obj) { back_ = obj; } +template +void IntrusiveList::Remove(const RefPtr& obj) { + if (!obj) { + return; + } + if (front_ == obj) { + front_ = obj->next_; + } + if (back_ == obj) { + back_ = obj->prev_; + } + if (obj->prev_) { + obj->prev_->next_ = obj->next_; + } + if (obj->next_) { + obj->next_->prev_ = obj->prev_; + } + + obj->prev_ = nullptr; + obj->next_ = nullptr; + size_--; +} + template RefPtr IntrusiveList::PopFront() { if (front_ == nullptr) {