diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-09-20 11:13:47 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-26 07:50:20 +0200 |
commit | f6e0aa3a0f3e5577b2672667d9e416d35dce849d (patch) | |
tree | 33e0d65fcfa0b0ecfdf5d9209aff8f1edca0d459 /src/corelib/tools/qhash.h | |
parent | bbd02d7086062991c9ddb561f0a5f4918171509a (diff) |
don't calculate hash when the map is empty and we are not inserting
the alternative would be splitting the function into two separate
overloads. that might result in better branch prediction, but will
create a bit more code.
Change-Id: Ia2c685bbb34a9681c71f2249d073dd960368209a
Reviewed-on: http://codereview.qt-project.org/5332
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r-- | src/corelib/tools/qhash.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index a2d9434904..55c3efa307 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -879,8 +879,13 @@ Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(cons uint *ahp) const { Node **node; - uint h = qHash(akey); + uint h; + if (d->numBuckets || ahp) { + h = qHash(akey); + if (ahp) + *ahp = h; + } if (d->numBuckets) { node = reinterpret_cast<Node **>(&d->buckets[h % d->numBuckets]); Q_ASSERT(*node == e || (*node)->next); @@ -889,8 +894,6 @@ Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(cons } else { node = const_cast<Node **>(reinterpret_cast<const Node * const *>(&e)); } - if (ahp) - *ahp = h; return node; } |