summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-10-26 09:30:49 +0100
committerLars Knoll <lars.knoll@qt.io>2020-11-03 16:28:14 +0100
commitf8c30759d98603908b408464ea6d98413fc81eec (patch)
treeed1f7828c517d9ebafb401fe8955eee45fdc44f1 /src/corelib/tools/qhash.h
parenta9c52dbdf47a6a070b84c8d34ae3c0c29a8ac1e8 (diff)
Make the QMultiHash(const QHash &) constructor explicit
And add a QMultiHash::unite(const QHash &) method to avoid a copy of the data when inserting a QHash into a multi hash. Change-Id: I864aa9d2b9b7b2c367c3c4d140a2ce2f5408ae09 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r--src/corelib/tools/qhash.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 67b3e026df..1f0d5d76ad 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -1219,7 +1219,7 @@ public:
return *this;
}
- QMultiHash(const QHash<Key, T> &other)
+ explicit QMultiHash(const QHash<Key, T> &other)
: QMultiHash(other.begin(), other.end())
{}
void swap(QMultiHash &other) noexcept { qSwap(d, other.d); qSwap(m_size, other.m_size); }
@@ -1808,6 +1808,13 @@ public:
return *this;
}
+ QMultiHash &unite(const QHash<Key, T> &other)
+ {
+ for (auto cit = other.cbegin(); cit != other.cend(); ++cit)
+ insert(cit.key(), *cit);
+ return *this;
+ }
+
QPair<iterator, iterator> equal_range(const Key &key)
{
detach();