From 5670d98c544c4bf2f9e7d081a03dbb92e87c4540 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 10 Nov 2022 16:46:19 +0100 Subject: [PATCH] util/IntrusiveList: move code to IntrusiveListNode::Connect() --- src/util/IntrusiveList.hxx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/util/IntrusiveList.hxx b/src/util/IntrusiveList.hxx index 56c93f778..76d2ae1b7 100644 --- a/src/util/IntrusiveList.hxx +++ b/src/util/IntrusiveList.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2020 Max Kellermann + * Copyright 2022 Max Kellermann * All rights reserved. * * author: Max Kellermann @@ -42,6 +42,12 @@ struct IntrusiveListNode { IntrusiveListNode *next, *prev; + + static constexpr void Connect(IntrusiveListNode &a, + IntrusiveListNode &b) noexcept { + a.next = &b; + b.prev = &a; + } }; class IntrusiveListHook { @@ -59,8 +65,7 @@ public: IntrusiveListHook &operator=(const IntrusiveListHook &) = delete; void unlink() noexcept { - siblings.next->prev = siblings.prev; - siblings.prev->next = siblings.next; + IntrusiveListNode::Connect(*siblings.prev, *siblings.next); } private: @@ -493,10 +498,9 @@ public: auto &existing_node = ToNode(*p); auto &new_node = ToNode(t); - existing_node.prev->next = &new_node; - new_node.prev = existing_node.prev; - existing_node.prev = &new_node; - new_node.next = &existing_node; + IntrusiveListNode::Connect(*existing_node.prev, + new_node); + IntrusiveListNode::Connect(new_node, existing_node); ++counter; }