summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-04-30 11:01:05 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-01 07:10:31 +0200
commitf9c2094e49f2f4bb5a5c3d76e7f78c0de7d720a8 (patch)
treeed4bc2f6b87dd543215a674555cd26b6097a8826 /src/corelib/tools/qhash.h
parent69218f58a97f5777c701c806e95ca31c5a277ddc (diff)
Restructure how we initialize hash nodes a little
This should help to silence coverity which was complaining hundreds of times about Qt not initializing h and next in QHashNode. Change-Id: Ib7977693e9786d4b310799e4f428115c65bb3fee Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r--src/corelib/tools/qhash.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index fe6a8dfad1..d196e6e376 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -197,27 +197,29 @@ inline bool operator==(const QHashDummyValue & /* v1 */, const QHashDummyValue &
Q_DECLARE_TYPEINFO(QHashDummyValue, Q_MOVABLE_TYPE | Q_DUMMY_TYPE);
template <class Key, class T>
-struct QHashDummyNode
+struct QHashNode
{
- QHashDummyNode *next;
+ QHashNode *next;
uint h;
Key key;
+ T value;
- inline QHashDummyNode(const Key &key0) : key(key0) {}
+ 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 <class Key, class T>
-struct QHashNode
+struct QHashDummyNode
{
- QHashNode *next;
+ QHashNode<Key, T> *next;
uint h;
Key key;
- T value;
- inline QHashNode(const Key &key0, const T &value0) : key(key0), value(value0) {}
- inline bool same_key(uint h0, const Key &key0) { return h0 == h && key0 == key; }
+ inline QHashDummyNode(const Key &key0, uint hash, QHashNode<Key, T> *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<Key, T>::duplicateNode(QHashData::Node *node, void
{
Node *concreteNode = concrete(node);
if (QTypeInfo<T>::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<Key, T>::createNode(uint ah, const Key &akey, const T &avalue, Node **anex
Node *node;
if (QTypeInfo<T>::isDummy) {
- node = reinterpret_cast<Node *>(new (d->allocateNode(alignOfDummyNode())) DummyNode(akey));
+ node = reinterpret_cast<Node *>(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;