Make QRegion::shared_empty const

Continuing the trend of QString, QVector, etc.

Change-Id: I8f53d4abfa0dd941bfdfd3c1a9049a42dbf92691
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2014-08-25 12:42:31 +02:00
parent 2045a657da
commit d93e4eff50
2 changed files with 13 additions and 18 deletions

View File

@ -240,7 +240,7 @@ QRegion::QRegion(int x, int y, int w, int h, RegionType t)
void QRegion::detach()
{
if (d->ref.load() != 1)
if (d->ref.isShared())
*this = copy();
}
@ -1588,7 +1588,7 @@ void QRegionPrivate::selfTest() const
#endif // QT_REGION_DEBUG
static QRegionPrivate qrp;
QRegion::QRegionData QRegion::shared_empty = {Q_BASIC_ATOMIC_INITIALIZER(1), &qrp};
const QRegion::QRegionData QRegion::shared_empty = {Q_REFCOUNT_INITIALIZE_STATIC, &qrp};
typedef void (*OverlapFunc)(QRegionPrivate &dest, const QRect *r1, const QRect *r1End,
const QRect *r2, const QRect *r2End, int y1, int y2);
@ -3786,19 +3786,17 @@ QRegionPrivate *qt_bitmapToRegion(const QBitmap& bitmap)
}
QRegion::QRegion()
: d(&shared_empty)
: d(const_cast<QRegionData*>(&shared_empty))
{
d->ref.ref();
}
QRegion::QRegion(const QRect &r, RegionType t)
{
if (r.isEmpty()) {
d = &shared_empty;
d->ref.ref();
d = const_cast<QRegionData*>(&shared_empty);
} else {
d = new QRegionData;
d->ref.store(1);
d->ref.initializeOwned();
if (t == Rectangle) {
d->qt_rgn = new QRegionPrivate(r);
} else if (t == Ellipse) {
@ -3817,15 +3815,13 @@ QRegion::QRegion(const QPolygon &a, Qt::FillRule fillRule)
fillRule == Qt::WindingFill ? WindingRule : EvenOddRule);
if (qt_rgn) {
d = new QRegionData;
d->ref.store(1);
d->ref.initializeOwned();
d->qt_rgn = qt_rgn;
} else {
d = &shared_empty;
d->ref.ref();
d = const_cast<QRegionData*>(&shared_empty);
}
} else {
d = &shared_empty;
d->ref.ref();
d = const_cast<QRegionData*>(&shared_empty);
}
}
@ -3839,11 +3835,10 @@ QRegion::QRegion(const QRegion &r)
QRegion::QRegion(const QBitmap &bm)
{
if (bm.isNull()) {
d = &shared_empty;
d->ref.ref();
d = const_cast<QRegionData*>(&shared_empty);
} else {
d = new QRegionData;
d->ref.store(1);
d->ref.initializeOwned();
d->qt_rgn = qt_bitmapToRegion(bm);
}
}
@ -3878,7 +3873,7 @@ QRegion QRegion::copy() const
{
QRegion r;
QScopedPointer<QRegionData> x(new QRegionData);
x->ref.store(1);
x->ref.initializeOwned();
if (d->qt_rgn)
x->qt_rgn = new QRegionPrivate(*d->qt_rgn);
else

View File

@ -150,11 +150,11 @@ Q_GUI_EXPORT
void exec(const QByteArray &ba, int ver = 0, QDataStream::ByteOrder byteOrder = QDataStream::BigEndian);
#endif
struct QRegionData {
QBasicAtomicInt ref;
QtPrivate::RefCount ref;
QRegionPrivate *qt_rgn;
};
struct QRegionData *d;
static struct QRegionData shared_empty;
static const struct QRegionData shared_empty;
static void cleanUp(QRegionData *x);
};