aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2019-04-25 18:23:43 +0300
committerKonstantin Ritt <ritt.ks@gmail.com>2019-09-10 17:15:11 +0300
commit1fec97053884d998442710a5d4258ffb6bed8955 (patch)
tree60529e7f3456f2558b571d5d32a3ff93800a22e1
parent0bcd8ed5c38a451e7458b820a25449c9cb408704 (diff)
QQuickIcon: prevent detach-ing when there is nothing to change
saves a bunch of pointless detach attempts on each deep-copy Change-Id: Ibb1ae99bd54b2d35f9c9aa9e541fb03891ad94ec Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquickicon.cpp13
-rw-r--r--src/quicktemplates2/qquickicon_p.h2
2 files changed, 14 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickicon.cpp b/src/quicktemplates2/qquickicon.cpp
index 61803e30..bf0a4658 100644
--- a/src/quicktemplates2/qquickicon.cpp
+++ b/src/quicktemplates2/qquickicon.cpp
@@ -112,12 +112,14 @@ void QQuickIcon::setName(const QString &name)
if ((d->resolveMask & QQuickIconPrivate::NameResolved) && d->name == name)
return;
+ d.detach();
d->name = name;
d->resolveMask |= QQuickIconPrivate::NameResolved;
}
void QQuickIcon::resetName()
{
+ d.detach();
d->name = QString();
d->resolveMask &= ~QQuickIconPrivate::NameResolved;
}
@@ -132,12 +134,14 @@ void QQuickIcon::setSource(const QUrl &source)
if ((d->resolveMask & QQuickIconPrivate::SourceResolved) && d->source == source)
return;
+ d.detach();
d->source = source;
d->resolveMask |= QQuickIconPrivate::SourceResolved;
}
void QQuickIcon::resetSource()
{
+ d.detach();
d->source = QString();
d->resolveMask &= ~QQuickIconPrivate::SourceResolved;
}
@@ -152,12 +156,14 @@ void QQuickIcon::setWidth(int width)
if ((d->resolveMask & QQuickIconPrivate::WidthResolved) && d->width == width)
return;
+ d.detach();
d->width = width;
d->resolveMask |= QQuickIconPrivate::WidthResolved;
}
void QQuickIcon::resetWidth()
{
+ d.detach();
d->width = 0;
d->resolveMask &= ~QQuickIconPrivate::WidthResolved;
}
@@ -172,12 +178,14 @@ void QQuickIcon::setHeight(int height)
if ((d->resolveMask & QQuickIconPrivate::HeightResolved) && d->height == height)
return;
+ d.detach();
d->height = height;
d->resolveMask |= QQuickIconPrivate::HeightResolved;
}
void QQuickIcon::resetHeight()
{
+ d.detach();
d->height = 0;
d->resolveMask &= ~QQuickIconPrivate::HeightResolved;
}
@@ -192,12 +200,14 @@ void QQuickIcon::setColor(const QColor &color)
if ((d->resolveMask & QQuickIconPrivate::ColorResolved) && d->color == color)
return;
+ d.detach();
d->color = color;
d->resolveMask |= QQuickIconPrivate::ColorResolved;
}
void QQuickIcon::resetColor()
{
+ d.detach();
d->color = Qt::transparent;
d->resolveMask &= ~QQuickIconPrivate::ColorResolved;
}
@@ -212,12 +222,14 @@ void QQuickIcon::setCache(bool cache)
if ((d->resolveMask & QQuickIconPrivate::CacheResolved) && d->cache == cache)
return;
+ d.detach();
d->cache = cache;
d->resolveMask |= QQuickIconPrivate::CacheResolved;
}
void QQuickIcon::resetCache()
{
+ d.detach();
d->cache = true;
d->resolveMask &= ~QQuickIconPrivate::CacheResolved;
}
@@ -225,6 +237,7 @@ void QQuickIcon::resetCache()
QQuickIcon QQuickIcon::resolve(const QQuickIcon &other) const
{
QQuickIcon resolved = *this;
+ resolved.d.detach();
if (!(d->resolveMask & QQuickIconPrivate::NameResolved))
resolved.d->name = other.d->name;
diff --git a/src/quicktemplates2/qquickicon_p.h b/src/quicktemplates2/qquickicon_p.h
index 57cab720..1835585d 100644
--- a/src/quicktemplates2/qquickicon_p.h
+++ b/src/quicktemplates2/qquickicon_p.h
@@ -107,7 +107,7 @@ public:
QQuickIcon resolve(const QQuickIcon &other) const;
private:
- QSharedDataPointer<QQuickIconPrivate> d;
+ QExplicitlySharedDataPointer<QQuickIconPrivate> d;
};
QT_END_NAMESPACE