From d1f080138a0bfaf845d051867c919bcb0e95c739 Mon Sep 17 00:00:00 2001 From: Jedrzej Nowacki Date: Fri, 10 Jun 2011 11:28:05 +0200 Subject: Cleanup reference counting in QIcon class It is better to use QSharedData and QExplicitlySharedDataPointer then doing manual ref counting. Change-Id: Icbb06d92102bcc906291238c5895a05e8d0e6de1 Reviewed-on: http://codereview.qt.nokia.com/1438 Reviewed-by: Qt Sanity Bot Reviewed-by: Olivier Goffart --- src/gui/image/qicon.cpp | 18 +++--------------- src/gui/image/qicon.h | 4 ++-- src/gui/image/qicon_p.h | 3 +-- 3 files changed, 6 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index e24087c3c5..7cf749fabc 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -116,7 +116,7 @@ static void qt_cleanup_icon_cache() } QIconPrivate::QIconPrivate() - : engine(0), ref(1), + : engine(0), serialNum(serialNumCounter.fetchAndAddRelaxed(1)), detach_no(0), engine_version(2), @@ -536,10 +536,7 @@ QIcon::QIcon(const QPixmap &pixmap) */ QIcon::QIcon(const QIcon &other) :d(other.d) -{ - if (d) - d->ref.ref(); -} +{} /*! Constructs an icon from the file with the given \a fileName. The @@ -593,10 +590,7 @@ QIcon::QIcon(QIconEngineV2 *engine) Destroys the icon. */ QIcon::~QIcon() -{ - if (d && !d->ref.deref()) - delete d; -} +{} /*! Assigns the \a other icon to this icon and returns a reference to @@ -604,10 +598,6 @@ QIcon::~QIcon() */ QIcon &QIcon::operator=(const QIcon &other) { - if (other.d) - other.d->ref.ref(); - if (d && !d->ref.deref()) - delete d; d = other.d; return *this; } @@ -775,8 +765,6 @@ void QIcon::detach() x->v1RefCount->ref(); } x->engine_version = d->engine_version; - if (!d->ref.deref()) - delete d; d = x; } ++d->detach_no; diff --git a/src/gui/image/qicon.h b/src/gui/image/qicon.h index 98bb2f8393..eb14384f78 100644 --- a/src/gui/image/qicon.h +++ b/src/gui/image/qicon.h @@ -132,14 +132,14 @@ public: Q_DUMMY_COMPARISON_OPERATOR(QIcon) private: - QIconPrivate *d; + QExplicitlySharedDataPointer d; #if !defined(QT_NO_DATASTREAM) friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); #endif public: - typedef QIconPrivate * DataPtr; + typedef QExplicitlySharedDataPointer DataPtr; inline DataPtr &data_ptr() { return d; } }; diff --git a/src/gui/image/qicon_p.h b/src/gui/image/qicon_p.h index 2708fd3f45..c5b4bb0ba7 100644 --- a/src/gui/image/qicon_p.h +++ b/src/gui/image/qicon_p.h @@ -63,7 +63,7 @@ #ifndef QT_NO_ICON QT_BEGIN_NAMESPACE -class QIconPrivate +class QIconPrivate : public QSharedData { public: QIconPrivate(); @@ -81,7 +81,6 @@ public: QIconEngine *engine; - QAtomicInt ref; int serialNum; int detach_no; int engine_version; -- cgit v1.2.3