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 <qt_sanity_bot@ovi.com> Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
This commit is contained in:
parent
eab215070e
commit
d1f080138a
@ -116,7 +116,7 @@ static void qt_cleanup_icon_cache()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QIconPrivate::QIconPrivate()
|
QIconPrivate::QIconPrivate()
|
||||||
: engine(0), ref(1),
|
: engine(0),
|
||||||
serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
|
serialNum(serialNumCounter.fetchAndAddRelaxed(1)),
|
||||||
detach_no(0),
|
detach_no(0),
|
||||||
engine_version(2),
|
engine_version(2),
|
||||||
@ -536,10 +536,7 @@ QIcon::QIcon(const QPixmap &pixmap)
|
|||||||
*/
|
*/
|
||||||
QIcon::QIcon(const QIcon &other)
|
QIcon::QIcon(const QIcon &other)
|
||||||
:d(other.d)
|
:d(other.d)
|
||||||
{
|
{}
|
||||||
if (d)
|
|
||||||
d->ref.ref();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Constructs an icon from the file with the given \a fileName. The
|
Constructs an icon from the file with the given \a fileName. The
|
||||||
@ -593,10 +590,7 @@ QIcon::QIcon(QIconEngineV2 *engine)
|
|||||||
Destroys the icon.
|
Destroys the icon.
|
||||||
*/
|
*/
|
||||||
QIcon::~QIcon()
|
QIcon::~QIcon()
|
||||||
{
|
{}
|
||||||
if (d && !d->ref.deref())
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Assigns the \a other icon to this icon and returns a reference to
|
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)
|
QIcon &QIcon::operator=(const QIcon &other)
|
||||||
{
|
{
|
||||||
if (other.d)
|
|
||||||
other.d->ref.ref();
|
|
||||||
if (d && !d->ref.deref())
|
|
||||||
delete d;
|
|
||||||
d = other.d;
|
d = other.d;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -775,8 +765,6 @@ void QIcon::detach()
|
|||||||
x->v1RefCount->ref();
|
x->v1RefCount->ref();
|
||||||
}
|
}
|
||||||
x->engine_version = d->engine_version;
|
x->engine_version = d->engine_version;
|
||||||
if (!d->ref.deref())
|
|
||||||
delete d;
|
|
||||||
d = x;
|
d = x;
|
||||||
}
|
}
|
||||||
++d->detach_no;
|
++d->detach_no;
|
||||||
|
@ -132,14 +132,14 @@ public:
|
|||||||
Q_DUMMY_COMPARISON_OPERATOR(QIcon)
|
Q_DUMMY_COMPARISON_OPERATOR(QIcon)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QIconPrivate *d;
|
QExplicitlySharedDataPointer<QIconPrivate> d;
|
||||||
#if !defined(QT_NO_DATASTREAM)
|
#if !defined(QT_NO_DATASTREAM)
|
||||||
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
|
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
|
||||||
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
|
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef QIconPrivate * DataPtr;
|
typedef QExplicitlySharedDataPointer<QIconPrivate> DataPtr;
|
||||||
inline DataPtr &data_ptr() { return d; }
|
inline DataPtr &data_ptr() { return d; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
#ifndef QT_NO_ICON
|
#ifndef QT_NO_ICON
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QIconPrivate
|
class QIconPrivate : public QSharedData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QIconPrivate();
|
QIconPrivate();
|
||||||
@ -81,7 +81,6 @@ public:
|
|||||||
|
|
||||||
QIconEngine *engine;
|
QIconEngine *engine;
|
||||||
|
|
||||||
QAtomicInt ref;
|
|
||||||
int serialNum;
|
int serialNum;
|
||||||
int detach_no;
|
int detach_no;
|
||||||
int engine_version;
|
int engine_version;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user