From 9f1e1eb5524fbf27a9fd2db4f1d98bb2bcd90077 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 15 Oct 2020 02:30:18 +0200 Subject: [PATCH] QHash: code tidies Apply std::exchange. Remove a wrong comment about MultiNode -- the compiler isn't generating any move operations, the move constructor is user-provided and there isn't a move assignment operator... Change-Id: Idd69458c69cc93e4575c119daba564e0046452c1 Reviewed-by: Lars Knoll --- src/corelib/tools/qhash.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index a1c1371e240..c6b82dbd338 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -185,9 +185,8 @@ struct MultiNode MultiNode(MultiNode &&other) : key(other.key), - value(other.value) + value(qExchange(other.value, nullptr)) { - other.value = nullptr; } MultiNode(const MultiNode &other) @@ -217,16 +216,13 @@ struct MultiNode void insertMulti(Args &&... args) { Chain *e = new Chain{ T(std::forward(args)...), nullptr }; - e->next = value; - value = e; + e->next = qExchange(value, e); } template void emplaceValue(Args &&... args) { value->value = T(std::forward(args)...); } - - // compiler generated move operators are fine }; template @@ -1212,10 +1208,10 @@ public: } return *this; } - QMultiHash(QMultiHash &&other) noexcept : d(other.d), m_size(other.m_size) + QMultiHash(QMultiHash &&other) noexcept + : d(qExchange(other.d, nullptr)), + m_size(qExchange(other.m_size, 0)) { - other.d = nullptr; - other.m_size = 0; } QMultiHash &operator=(QMultiHash &&other) noexcept(std::is_nothrow_destructible::value) {