From f6e0aa3a0f3e5577b2672667d9e416d35dce849d Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 20 Sep 2011 11:13:47 +0200 Subject: don't calculate hash when the map is empty and we are not inserting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Samuel Rødal Reviewed-by: Lars Knoll --- src/corelib/tools/qhash.h | 9 ++++++--- 1 file 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::Node **QHash::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(&d->buckets[h % d->numBuckets]); Q_ASSERT(*node == e || (*node)->next); @@ -889,8 +894,6 @@ Q_OUTOFLINE_TEMPLATE typename QHash::Node **QHash::findNode(cons } else { node = const_cast(reinterpret_cast(&e)); } - if (ahp) - *ahp = h; return node; } -- cgit v1.2.3