Make QLinkedListData::shared_null const

Similar to QList, QMap, QVector, QByteArray and QString, keep the
shared_null in shareable memory and never modify it.

Change-Id: I70b484d528c397a9d205b1418b6dc920c69dc725
Reviewed-on: http://codereview.qt-project.org/4532
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
Bradley T. Hughes 2011-09-09 11:10:48 +02:00 committed by Qt by Nokia
parent 1173d0420e
commit f8f501ec98
2 changed files with 8 additions and 7 deletions

View File

@ -43,9 +43,10 @@
QT_BEGIN_NAMESPACE
QLinkedListData QLinkedListData::shared_null = {
&QLinkedListData::shared_null, &QLinkedListData::shared_null,
Q_BASIC_ATOMIC_INITIALIZER(1), 0, true
const QLinkedListData QLinkedListData::shared_null = {
const_cast<QLinkedListData *>(&QLinkedListData::shared_null),
const_cast<QLinkedListData *>(&QLinkedListData::shared_null),
Q_REFCOUNT_INITIALIZER(-1), 0, true
};
/*! \class QLinkedList

View File

@ -43,7 +43,7 @@
#define QLINKEDLIST_H
#include <QtCore/qiterator.h>
#include <QtCore/qatomic.h>
#include <QtCore/qrefcount.h>
#ifndef QT_NO_STL
#include <iterator>
@ -59,11 +59,11 @@ QT_MODULE(Core)
struct Q_CORE_EXPORT QLinkedListData
{
QLinkedListData *n, *p;
QBasicAtomicInt ref;
QtPrivate::RefCount ref;
int size;
uint sharable : 1;
static QLinkedListData shared_null;
static const QLinkedListData shared_null;
};
template <typename T>
@ -81,7 +81,7 @@ class QLinkedList
union { QLinkedListData *d; QLinkedListNode<T> *e; };
public:
inline QLinkedList() : d(&QLinkedListData::shared_null) { d->ref.ref(); }
inline QLinkedList() : d(const_cast<QLinkedListData *>(&QLinkedListData::shared_null)) { }
inline QLinkedList(const QLinkedList<T> &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach(); }
~QLinkedList();
QLinkedList<T> &operator=(const QLinkedList<T> &);