diff --git a/panda/src/putil/linkedListNode.I b/panda/src/putil/linkedListNode.I index faed3b5c96..a61aaa854c 100644 --- a/panda/src/putil/linkedListNode.I +++ b/panda/src/putil/linkedListNode.I @@ -33,6 +33,25 @@ LinkedListNode(bool) { _prev = this; } +/** + * This move constructor replaces the other link with this one. + */ +INLINE LinkedListNode:: +LinkedListNode(LinkedListNode &&from) noexcept { + if (from._prev != nullptr) { + nassertv(from._prev->_next == &from); + from._prev->_next = this; + } + _prev = from._prev; + if (from._next != nullptr) { + nassertv(from._next->_prev == &from); + from._next->_prev = this; + } + _next = from._next; + from._next = nullptr; + from._prev = nullptr; +} + /** * */ @@ -41,6 +60,23 @@ INLINE LinkedListNode:: nassertv((_next == nullptr && _prev == nullptr) || (_next == this && _prev == this)); } +/** + * Replaces the given other node with this node. + */ +INLINE LinkedListNode &LinkedListNode:: +operator = (LinkedListNode &&from) { + nassertr((_next == nullptr && _prev == nullptr) || (_next == this && _prev == this), *this); + nassertr(from._prev != nullptr && from._next != nullptr, *this); + nassertr(from._prev->_next == &from && from._next->_prev == &from, *this); + from._prev->_next = this; + from._next->_prev = this; + _prev = from._prev; + _next = from._next; + from._next = nullptr; + from._prev = nullptr; + return *this; +} + /** * Returns true if the node is member of any list, false if it has been * removed or never added. The head of a list generally appears to to always diff --git a/panda/src/putil/linkedListNode.h b/panda/src/putil/linkedListNode.h index 9dedbe9e4d..5f8e6f1909 100644 --- a/panda/src/putil/linkedListNode.h +++ b/panda/src/putil/linkedListNode.h @@ -32,8 +32,11 @@ class EXPCL_PANDA_PUTIL LinkedListNode { protected: INLINE LinkedListNode(); INLINE LinkedListNode(bool); + INLINE LinkedListNode(LinkedListNode &&from) noexcept; INLINE ~LinkedListNode(); + INLINE LinkedListNode &operator = (LinkedListNode &&from); + INLINE bool is_on_list() const; INLINE void remove_from_list(); INLINE void insert_before(LinkedListNode *node);