util/IntrusiveList: move code to IntrusiveListNode::Connect()

This commit is contained in:
Max Kellermann 2022-11-10 16:46:19 +01:00
parent 440c676be2
commit 5670d98c54

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020 Max Kellermann <max.kellermann@gmail.com> * Copyright 2022 Max Kellermann <max.kellermann@gmail.com>
* All rights reserved. * All rights reserved.
* *
* author: Max Kellermann <mk@cm4all.com> * author: Max Kellermann <mk@cm4all.com>
@ -42,6 +42,12 @@
struct IntrusiveListNode { struct IntrusiveListNode {
IntrusiveListNode *next, *prev; IntrusiveListNode *next, *prev;
static constexpr void Connect(IntrusiveListNode &a,
IntrusiveListNode &b) noexcept {
a.next = &b;
b.prev = &a;
}
}; };
class IntrusiveListHook { class IntrusiveListHook {
@ -59,8 +65,7 @@ public:
IntrusiveListHook &operator=(const IntrusiveListHook &) = delete; IntrusiveListHook &operator=(const IntrusiveListHook &) = delete;
void unlink() noexcept { void unlink() noexcept {
siblings.next->prev = siblings.prev; IntrusiveListNode::Connect(*siblings.prev, *siblings.next);
siblings.prev->next = siblings.next;
} }
private: private:
@ -493,10 +498,9 @@ public:
auto &existing_node = ToNode(*p); auto &existing_node = ToNode(*p);
auto &new_node = ToNode(t); auto &new_node = ToNode(t);
existing_node.prev->next = &new_node; IntrusiveListNode::Connect(*existing_node.prev,
new_node.prev = existing_node.prev; new_node);
existing_node.prev = &new_node; IntrusiveListNode::Connect(new_node, existing_node);
new_node.next = &existing_node;
++counter; ++counter;
} }