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 <lars.knoll@qt.io>
This commit is contained in:
Giuseppe D'Angelo 2020-10-15 02:30:18 +02:00
parent 9fa848dcaf
commit 9f1e1eb552

View File

@ -185,9 +185,8 @@ struct MultiNode
MultiNode(MultiNode &&other) MultiNode(MultiNode &&other)
: key(other.key), : key(other.key),
value(other.value) value(qExchange(other.value, nullptr))
{ {
other.value = nullptr;
} }
MultiNode(const MultiNode &other) MultiNode(const MultiNode &other)
@ -217,16 +216,13 @@ struct MultiNode
void insertMulti(Args &&... args) void insertMulti(Args &&... args)
{ {
Chain *e = new Chain{ T(std::forward<Args>(args)...), nullptr }; Chain *e = new Chain{ T(std::forward<Args>(args)...), nullptr };
e->next = value; e->next = qExchange(value, e);
value = e;
} }
template<typename ...Args> template<typename ...Args>
void emplaceValue(Args &&... args) void emplaceValue(Args &&... args)
{ {
value->value = T(std::forward<Args>(args)...); value->value = T(std::forward<Args>(args)...);
} }
// compiler generated move operators are fine
}; };
template<typename Node> template<typename Node>
@ -1212,10 +1208,10 @@ public:
} }
return *this; 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<Node>::value) QMultiHash &operator=(QMultiHash &&other) noexcept(std::is_nothrow_destructible<Node>::value)
{ {