summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorSérgio Martins <sergio.martins@kdab.com>2015-05-27 11:20:57 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-05-30 07:15:12 +0000
commitfda08f3971e854ad1623fb99212746143c27e412 (patch)
tree654784457f67f5fefb2e5f5e73f09ea7ee4b86fd /src/corelib
parent21ec751cdcf2f5aa4c14a040edbe26b0cb3b2540 (diff)
QHash: Add a findNode() overload that doesn't calculate hash
Needed for QSet::intersects() for optimization purposes. No need to calculate the hash when we already have it. Change-Id: I247602bb0558ca8d1fb8333de9d5f339146c576d Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qhash.h24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index c4c8c8f3cc..3d713146fe 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -451,6 +451,7 @@ private:
void detach_helper();
void freeData(QHashData *d);
Node **findNode(const Key &key, uint *hp = 0) const;
+ Node **findNode(const Key &key, uint h) const;
Node *createNode(uint h, const Key &key, const T &value, Node **nextNode);
void deleteNode(Node *node);
static void deleteNode2(QHashData::Node *node);
@@ -846,17 +847,10 @@ Q_INLINE_TEMPLATE bool QHash<Key, T>::contains(const Key &akey) const
}
template <class Key, class T>
-Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(const Key &akey,
- uint *ahp) const
+Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(const Key &akey, uint h) const
{
Node **node;
- uint h = 0;
- if (d->numBuckets || ahp) {
- h = qHash(akey, d->seed);
- if (ahp)
- *ahp = h;
- }
if (d->numBuckets) {
node = reinterpret_cast<Node **>(&d->buckets[h % d->numBuckets]);
Q_ASSERT(*node == e || (*node)->next);
@@ -869,6 +863,20 @@ Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(cons
}
template <class Key, class T>
+Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(const Key &akey,
+ uint *ahp) const
+{
+ uint h = 0;
+
+ if (d->numBuckets || ahp) {
+ h = qHash(akey, d->seed);
+ if (ahp)
+ *ahp = h;
+ }
+ return findNode(akey, h);
+}
+
+template <class Key, class T>
Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash &other) const
{
if (size() != other.size())