summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-10-15 02:30:18 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-10-16 01:07:57 +0200
commit9f1e1eb5524fbf27a9fd2db4f1d98bb2bcd90077 (patch)
tree9572d3dcc0b977b6ab45859715538715f4c8da82 /src/corelib/tools/qhash.h
parent9fa848dcaf18bb4af35252347168786816ba8850 (diff)
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>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r--src/corelib/tools/qhash.h14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index a1c1371e24..c6b82dbd33 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>(args)...), nullptr };
- e->next = value;
- value = e;
+ e->next = qExchange(value, e);
}
template<typename ...Args>
void emplaceValue(Args &&... args)
{
value->value = T(std::forward<Args>(args)...);
}
-
- // compiler generated move operators are fine
};
template<typename Node>
@@ -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<Node>::value)
{