summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2011-09-09 11:09:16 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-26 07:50:20 +0200
commitcc3bf12ef69c086069835585f298fe603e632aed (patch)
treed822b1e46274abcf4d339dfcc7266c77eeb11350 /src
parentf8f501ec9853231805097a5dbaf0ea99196e8014 (diff)
Make QListData::shared_null const
Similar to QMap, QVector, QByteArray and QString, keep the shared_null in shareable memory and never modify it. Change-Id: I2b4bb8de564080021043f6ede6c903d567c686cf Reviewed-on: http://codereview.qt-project.org/4531 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlist.cpp2
-rw-r--r--src/corelib/tools/qlist.h15
2 files changed, 9 insertions, 8 deletions
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index 4c04385033..0daec4dbd9 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
the number of elements in the list.
*/
-QListData::Data QListData::shared_null = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, 0, true, { 0 } };
+const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, true, { 0 } };
static int grow(int size)
{
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index a215cc689a..e9e44dbb10 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -42,9 +42,9 @@
#ifndef QLIST_H
#define QLIST_H
-#include <QtCore/qiterator.h>
-#include <QtCore/qatomic.h>
#include <QtCore/qalgorithms.h>
+#include <QtCore/qiterator.h>
+#include <QtCore/qrefcount.h>
#ifndef QT_NO_STL
#include <iterator>
@@ -70,7 +70,7 @@ template <typename T> class QSet;
struct Q_CORE_EXPORT QListData {
struct Data {
- QBasicAtomicInt ref;
+ QtPrivate::RefCount ref;
int alloc, begin, end;
uint sharable : 1;
void *array[1];
@@ -80,7 +80,7 @@ struct Q_CORE_EXPORT QListData {
Data *detach(int alloc);
Data *detach_grow(int *i, int n);
void realloc(int alloc);
- static Data shared_null;
+ static const Data shared_null;
Data *d;
void **erase(void **xi);
void **append(int n);
@@ -114,7 +114,7 @@ class QList
union { QListData p; QListData::Data *d; };
public:
- inline QList() : d(&QListData::shared_null) { d->ref.ref(); }
+ inline QList() : d(const_cast<QListData::Data *>(&QListData::shared_null)) { }
inline QList(const QList<T> &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach_helper(); }
~QList();
QList<T> &operator=(const QList<T> &l);
@@ -124,8 +124,9 @@ public:
#endif
inline void swap(QList<T> &other) { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS
- inline QList(std::initializer_list<T> args) : d(&QListData::shared_null)
- { d->ref.ref(); qCopy(args.begin(), args.end(), std::back_inserter(*this)); }
+ inline QList(std::initializer_list<T> args)
+ : d(const_cast<QListData::Data *>(&QListData::shared_null))
+ { qCopy(args.begin(), args.end(), std::back_inserter(*this)); }
#endif
bool operator==(const QList<T> &l) const;
inline bool operator!=(const QList<T> &l) const { return !(*this == l); }