summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2011-09-09 11:18:28 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-26 07:50:20 +0200
commit1173d0420e341dc6d38c89e5bc4295a57da7ea74 (patch)
treefe34ad5647d12c0bc245499acca5bc4c3566407c
parentf6e0aa3a0f3e5577b2672667d9e416d35dce849d (diff)
Make QHashData::shared_null const
Similar to QLinkedList QList, QMap, QVector, QByteArray and QString, keep the shared_null in shareable memory and never modify it. Change-Id: Ia8b72ef0288575bed658153d9d54434580988bda Reviewed-on: http://codereview.qt-project.org/4533 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
-rw-r--r--src/corelib/tools/qhash.cpp4
-rw-r--r--src/corelib/tools/qhash.h8
2 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index f43e888b61..2e60f40a9c 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -165,8 +165,8 @@ static int countBits(int hint)
*/
const int MinNumBits = 4;
-QHashData QHashData::shared_null = {
- 0, 0, Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, MinNumBits, 0, 0, true, false, 0
+const QHashData QHashData::shared_null = {
+ 0, 0, Q_REFCOUNT_INITIALIZER(-1), 0, 0, MinNumBits, 0, 0, true, false, 0
};
void *QHashData::allocateNode()
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 55c3efa307..40a58fdbf8 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -42,11 +42,11 @@
#ifndef QHASH_H
#define QHASH_H
-#include <QtCore/qatomic.h>
#include <QtCore/qchar.h>
#include <QtCore/qiterator.h>
#include <QtCore/qlist.h>
#include <QtCore/qpair.h>
+#include <QtCore/qrefcount.h>
QT_BEGIN_HEADER
@@ -118,7 +118,7 @@ struct Q_CORE_EXPORT QHashData
Node *fakeNext;
Node **buckets;
- QBasicAtomicInt ref;
+ QtPrivate::RefCount ref;
int size;
int nodeSize;
short userNumBits;
@@ -148,7 +148,7 @@ struct Q_CORE_EXPORT QHashData
static Node *nextNode(Node *node);
static Node *previousNode(Node *node);
- static QHashData shared_null;
+ static const QHashData shared_null;
};
inline void QHashData::mightGrow() // ### Qt 5: eliminate
@@ -278,7 +278,7 @@ class QHash
#endif
public:
- inline QHash() : d(&QHashData::shared_null) { d->ref.ref(); }
+ inline QHash() : d(const_cast<QHashData *>(&QHashData::shared_null)) { }
inline QHash(const QHash<Key, T> &other) : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); }
inline ~QHash() { if (!d->ref.deref()) freeData(d); }