diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index a2851d15bd5..10dcff92c7d 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -369,7 +369,6 @@ QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *), QT_RETHROW; } - dup->h = oldNode->h; *nextNode = dup; nextNode = &dup->next; oldNode = oldNode->next; diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index fe6a8dfad14..d196e6e3763 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -196,16 +196,6 @@ inline bool operator==(const QHashDummyValue & /* v1 */, const QHashDummyValue & Q_DECLARE_TYPEINFO(QHashDummyValue, Q_MOVABLE_TYPE | Q_DUMMY_TYPE); -template -struct QHashDummyNode -{ - QHashDummyNode *next; - uint h; - Key key; - - inline QHashDummyNode(const Key &key0) : key(key0) {} -}; - template struct QHashNode { @@ -214,10 +204,22 @@ struct QHashNode Key key; T value; - inline QHashNode(const Key &key0, const T &value0) : key(key0), value(value0) {} + inline QHashNode(const Key &key0, const T &value0, uint hash, QHashNode *n) + : next(n), h(hash), key(key0), value(value0) {} inline bool same_key(uint h0, const Key &key0) { return h0 == h && key0 == key; } }; +template +struct QHashDummyNode +{ + QHashNode *next; + uint h; + Key key; + + inline QHashDummyNode(const Key &key0, uint hash, QHashNode *n) : next(n), h(hash), key(key0) {} +}; + + #if 0 // ### // The introduction of the QHash random seed breaks this optimization, as it @@ -519,9 +521,9 @@ Q_INLINE_TEMPLATE void QHash::duplicateNode(QHashData::Node *node, void { Node *concreteNode = concrete(node); if (QTypeInfo::isDummy) { - (void) new (newNode) DummyNode(concreteNode->key); + (void) new (newNode) DummyNode(concreteNode->key, concreteNode->h, 0); } else { - (void) new (newNode) Node(concreteNode->key, concreteNode->value); + (void) new (newNode) Node(concreteNode->key, concreteNode->value, concreteNode->h, 0); } } @@ -532,13 +534,11 @@ QHash::createNode(uint ah, const Key &akey, const T &avalue, Node **anex Node *node; if (QTypeInfo::isDummy) { - node = reinterpret_cast(new (d->allocateNode(alignOfDummyNode())) DummyNode(akey)); + node = reinterpret_cast(new (d->allocateNode(alignOfDummyNode())) DummyNode(akey, ah, *anextNode)); } else { - node = new (d->allocateNode(alignOfNode())) Node(akey, avalue); + node = new (d->allocateNode(alignOfNode())) Node(akey, avalue, ah, *anextNode); } - node->h = ah; - node->next = *anextNode; *anextNode = node; ++d->size; return node;