From 564086b366427da27eb1573e82fda7ab62dc4a17 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Fri, 9 Sep 2011 11:08:25 +0200 Subject: 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 Reviewed-by: Oswald Buddenhagen --- src/corelib/tools/qmap.cpp | 8 ++++---- src/corelib/tools/qmap.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index aecc73c8dd..bd7c76c37a 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -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(&shared_null), + { const_cast(&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() diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 771959a3bf..ff181d5071 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -42,9 +42,9 @@ #ifndef QMAP_H #define QMAP_H -#include #include #include +#include #ifndef QT_NO_STL #include @@ -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::shared_null)) { } inline QMap(const QMap &other) : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); } inline ~QMap() { if (!d) return; if (!d->ref.deref()) freeData(d); } -- cgit v1.2.3