From 75e8795e3ff0c8c6a1c56c219fbe66b1b1006f40 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 17 Feb 2021 20:14:29 +0100 Subject: [PATCH] util/IntrusiveList: add method insert() --- src/util/IntrusiveList.hxx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/util/IntrusiveList.hxx b/src/util/IntrusiveList.hxx index 33c97b43f..f38645539 100644 --- a/src/util/IntrusiveList.hxx +++ b/src/util/IntrusiveList.hxx @@ -317,18 +317,20 @@ public: } void push_front(T &t) noexcept { - auto &new_node = ToNode(t); - head.next->prev = &new_node; - new_node.next = head.next; - head.next = &new_node; - new_node.prev = &head; + insert(begin(), t); } void push_back(T &t) noexcept { + insert(end(), t); + } + + void insert(iterator p, T &t) noexcept { + auto &existing_node = ToNode(*p); auto &new_node = ToNode(t); - head.prev->next = &new_node; - new_node.prev = head.prev; - head.prev = &new_node; - new_node.next = &head; + + existing_node.prev->next = &new_node; + new_node.prev = existing_node.prev; + existing_node.prev = &new_node; + new_node.next = &existing_node; } };