Make QMapData::shared_null const
Similar to QVector, QByteArray and QString, keep the shared_null in shareable memory and never modify it. Change-Id: I062825684b79f2b01ec7ce65e0cf74f417b760b8 Reviewed-on: http://codereview.qt-project.org/4530 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>bb10
parent
cc3bf12ef6
commit
564086b366
|
|
@ -50,10 +50,10 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QMapData QMapData::shared_null = {
|
||||
&shared_null,
|
||||
{ &shared_null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, 0, false, true, false, 0
|
||||
const QMapData QMapData::shared_null = {
|
||||
const_cast<QMapData *>(&shared_null),
|
||||
{ const_cast<QMapData *>(&shared_null), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
Q_REFCOUNT_INITIALIZER(-1), 0, 0, 0, false, true, false, 0
|
||||
};
|
||||
|
||||
QMapData *QMapData::createData()
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@
|
|||
#ifndef QMAP_H
|
||||
#define QMAP_H
|
||||
|
||||
#include <QtCore/qatomic.h>
|
||||
#include <QtCore/qiterator.h>
|
||||
#include <QtCore/qlist.h>
|
||||
#include <QtCore/qrefcount.h>
|
||||
|
||||
#ifndef QT_NO_STL
|
||||
#include <map>
|
||||
|
|
@ -68,7 +68,7 @@ struct Q_CORE_EXPORT QMapData
|
|||
|
||||
QMapData *backward;
|
||||
QMapData *forward[QMapData::LastLevel + 1];
|
||||
QBasicAtomicInt ref;
|
||||
QtPrivate::RefCount ref;
|
||||
int topLevel;
|
||||
int size;
|
||||
uint randomBits;
|
||||
|
|
@ -88,7 +88,7 @@ struct Q_CORE_EXPORT QMapData
|
|||
void dump();
|
||||
#endif
|
||||
|
||||
static QMapData shared_null;
|
||||
static const QMapData shared_null;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ class QMap
|
|||
}
|
||||
|
||||
public:
|
||||
inline QMap() : d(&QMapData::shared_null) { d->ref.ref(); }
|
||||
inline QMap() : d(const_cast<QMapData *>(&QMapData::shared_null)) { }
|
||||
inline QMap(const QMap<Key, T> &other) : d(other.d)
|
||||
{ d->ref.ref(); if (!d->sharable) detach(); }
|
||||
inline ~QMap() { if (!d) return; if (!d->ref.deref()) freeData(d); }
|
||||
|
|
|
|||
Loading…
Reference in New Issue