summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-15 13:23:02 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-16 09:48:09 +0200
commitada6e4fbe9f363a33d4f9341bbc468d22c0c1442 (patch)
tree41abb0dfbd9c3dc5566d4679ceee6a6f673e97de /src
parentb002c48cc799ebe613ed5fadebd0f5956e214388 (diff)
Fix some bad uses of QSharedPointerData::operator T*
Avoid detaching where possible Change-Id: I438d3e66689aeef05951af86a48af2a6910da7c2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qprocess.cpp8
-rw-r--r--src/corelib/io/qurlquery.cpp14
-rw-r--r--src/corelib/text/qregularexpression.cpp6
-rw-r--r--src/corelib/time/qtimezone.cpp6
-rw-r--r--src/gui/text/qtextformat.cpp14
-rw-r--r--src/network/access/qabstractnetworkcache.cpp20
-rw-r--r--src/network/ssl/qsslconfiguration.cpp5
-rw-r--r--src/network/ssl/qsslcontext_openssl.cpp2
8 files changed, 40 insertions, 35 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index 826f421eee..8b29a8964f 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -290,7 +290,7 @@ bool QProcessEnvironment::isEmpty() const
*/
void QProcessEnvironment::clear()
{
- if (d)
+ if (d.constData())
d->vars.clear();
// Unix: Don't clear d->nameMap, as the environment is likely to be
// re-populated with the same keys again.
@@ -339,9 +339,9 @@ void QProcessEnvironment::insert(const QString &name, const QString &value)
*/
void QProcessEnvironment::remove(const QString &name)
{
- if (d) {
- d.detach(); // detach before prepareName()
- d->vars.remove(d->prepareName(name));
+ if (d.constData()) {
+ QProcessEnvironmentPrivate *p = d.data();
+ p->vars.remove(p->prepareName(name));
}
}
diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp
index b889eb131b..a836fb2e99 100644
--- a/src/corelib/io/qurlquery.cpp
+++ b/src/corelib/io/qurlquery.cpp
@@ -743,9 +743,10 @@ QStringList QUrlQuery::allQueryItemValues(const QString &key, QUrl::ComponentFor
void QUrlQuery::removeQueryItem(const QString &key)
{
if (d.constData()) {
- Map::iterator it = d->findKey(key);
- if (it != d->itemList.end())
- d->itemList.erase(it);
+ auto *p = d.data();
+ Map::iterator it = p->findKey(key);
+ if (it != p->itemList.end())
+ p->itemList.erase(it);
}
}
@@ -758,12 +759,13 @@ void QUrlQuery::removeQueryItem(const QString &key)
void QUrlQuery::removeAllQueryItems(const QString &key)
{
if (d.constData()) {
- const QString encodedKey = d->recodeFromUser(key);
+ auto *p = d.data();
+ const QString encodedKey = p->recodeFromUser(key);
auto firstEqualsEncodedKey = [&encodedKey](const QPair<QString, QString> &item) {
return item.first == encodedKey;
};
- const auto end = d->itemList.end();
- d->itemList.erase(std::remove_if(d->itemList.begin(), end, firstEqualsEncodedKey), end);
+ const auto end = p->itemList.end();
+ p->itemList.erase(std::remove_if(p->itemList.begin(), end, firstEqualsEncodedKey), end);
}
}
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index 1ca1cadaa3..45ed3f806a 100644
--- a/src/corelib/text/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
@@ -2569,11 +2569,11 @@ QRegularExpressionMatch QRegularExpressionMatchIterator::next()
{
if (!hasNext()) {
qWarning("QRegularExpressionMatchIterator::next() called on an iterator already at end");
- return d->next;
+ return d.constData()->next;
}
- QRegularExpressionMatch current = d->next;
- d->next = d->next.d.constData()->nextMatch();
+ QRegularExpressionMatch current = d.constData()->next;
+ d->next = current.d.constData()->nextMatch();
return current;
}
diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp
index e95700c64b..5f4589eda0 100644
--- a/src/corelib/time/qtimezone.cpp
+++ b/src/corelib/time/qtimezone.cpp
@@ -112,7 +112,7 @@ public:
// isTimeZoneIdAvailable() and to create named IANA time zones. This is usually the host
// system, but may be different if the host resources are insufficient or if
// QT_NO_SYSTEMLOCALE is set. A simple UTC backend is used if no alternative is available.
- QSharedDataPointer<QTimeZonePrivate> backend;
+ QExplicitlySharedDataPointer<QTimeZonePrivate> backend;
};
Q_GLOBAL_STATIC(QTimeZoneSingleton, global_tz);
@@ -339,11 +339,11 @@ QTimeZone::QTimeZone(const QByteArray &ianaId)
d = new QUtcTimeZonePrivate(ianaId);
// If not a CLDR UTC offset ID then try creating it with the system backend.
// Relies on backend not creating valid TZ with invalid name.
- if (!d->isValid())
+ if (!d.constData()->isValid())
d = ianaId.isEmpty() ? newBackendTimeZone() : newBackendTimeZone(ianaId);
// Can also handle UTC with arbitrary (valid) offset, but only do so as
// fall-back, since either of the above may handle it more informatively.
- if (!d->isValid()) {
+ if (!d.constData()->isValid()) {
qint64 offset = QUtcTimeZonePrivate::offsetFromUtcString(ianaId);
if (offset != QTimeZonePrivate::invalidSeconds()) {
// Should have abs(offset) < 24 * 60 * 60 = 86400.
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index af1fdfa653..850b4ad43d 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -919,13 +919,13 @@ void QTextFormat::merge(const QTextFormat &other)
if (!other.d)
return;
- QTextFormatPrivate *d = this->d;
+ QTextFormatPrivate *p = d.data();
- const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d->props;
- d->props.reserve(d->props.size() + otherProps.size());
+ const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d.constData()->props;
+ p->props.reserve(p->props.size() + otherProps.size());
for (int i = 0; i < otherProps.count(); ++i) {
- const QT_PREPEND_NAMESPACE(Property) &p = otherProps.at(i);
- d->insertProperty(p.key, p.value);
+ const QT_PREPEND_NAMESPACE(Property) &prop = otherProps.at(i);
+ p->insertProperty(prop.key, prop.value);
}
}
@@ -1261,10 +1261,10 @@ int QTextFormat::objectIndex() const
void QTextFormat::setObjectIndex(int o)
{
if (o == -1) {
- if (d)
+ if (d.constData())
d->clearProperty(ObjectIndex);
} else {
- if (!d)
+ if (!d.constData())
d = new QTextFormatPrivate;
// ### type
d->insertProperty(ObjectIndex, o);
diff --git a/src/network/access/qabstractnetworkcache.cpp b/src/network/access/qabstractnetworkcache.cpp
index 4e217294c4..06e21d1b88 100644
--- a/src/network/access/qabstractnetworkcache.cpp
+++ b/src/network/access/qabstractnetworkcache.cpp
@@ -232,9 +232,10 @@ QUrl QNetworkCacheMetaData::url() const
*/
void QNetworkCacheMetaData::setUrl(const QUrl &url)
{
- d->url = url;
- d->url.setPassword(QString());
- d->url.setFragment(QString());
+ auto *p = d.data();
+ p->url = url;
+ p->url.setPassword(QString());
+ p->url.setFragment(QString());
}
/*!
@@ -395,12 +396,13 @@ static inline QDataStream &operator>>(QDataStream &in, QNetworkCacheMetaData::At
void QNetworkCacheMetaDataPrivate::load(QDataStream &in, QNetworkCacheMetaData &metaData)
{
- in >> metaData.d->url;
- in >> metaData.d->expirationDate;
- in >> metaData.d->lastModified;
- in >> metaData.d->saveToDisk;
- in >> metaData.d->attributes;
- in >> metaData.d->headers;
+ auto *p = metaData.d.data();
+ in >> p->url;
+ in >> p->expirationDate;
+ in >> p->lastModified;
+ in >> p->saveToDisk;
+ in >> p->attributes;
+ in >> p->headers;
}
/*!
diff --git a/src/network/ssl/qsslconfiguration.cpp b/src/network/ssl/qsslconfiguration.cpp
index 4b41d84633..916774db04 100644
--- a/src/network/ssl/qsslconfiguration.cpp
+++ b/src/network/ssl/qsslconfiguration.cpp
@@ -630,12 +630,13 @@ void QSslConfiguration::setCiphers(const QList<QSslCipher> &ciphers)
*/
void QSslConfiguration::setCiphers(const QString &ciphers)
{
- d->ciphers.clear();
+ auto *p = d.data();
+ p->ciphers.clear();
const auto cipherNames = ciphers.split(QLatin1Char(':'), Qt::SkipEmptyParts);
for (const QString &cipherName : cipherNames) {
QSslCipher cipher(cipherName);
if (!cipher.isNull())
- d->ciphers << cipher;
+ p->ciphers << cipher;
}
}
diff --git a/src/network/ssl/qsslcontext_openssl.cpp b/src/network/ssl/qsslcontext_openssl.cpp
index 5fb7172583..a8d92bd80d 100644
--- a/src/network/ssl/qsslcontext_openssl.cpp
+++ b/src/network/ssl/qsslcontext_openssl.cpp
@@ -194,7 +194,7 @@ SSL* QSslContext::createSsl()
}
#ifndef OPENSSL_NO_NEXTPROTONEG
- QList<QByteArray> protocols = sslConfiguration.d->nextAllowedProtocols;
+ QList<QByteArray> protocols = sslConfiguration.d.constData()->nextAllowedProtocols;
if (!protocols.isEmpty()) {
m_supportedNPNVersions.clear();
for (int a = 0; a < protocols.count(); ++a) {