summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-01-15 09:56:06 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2020-01-16 08:30:41 +0000
commit6faaef5a665f86465d616f20b5effd2ba650cee7 (patch)
treef1f0710179ab1e1564ac1e4e4a61fd77eaf8ed97
parentbd828bacb982a51ee21f03487f8390cfc96cc6d3 (diff)
QNetworkAccessManager: Avoid unnecessary calls to sender()
As it searches through all connections, of which we have multiple for each network reply. Fixes: QTBUG-81336 Change-Id: Iba28278edae5f254bf884f427e0944d348b47d03 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp23
-rw-r--r--src/network/access/qnetworkaccessmanager.h2
-rw-r--r--src/network/access/qnetworkaccessmanager_p.h4
3 files changed, 12 insertions, 17 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index ff916ff283..1f05fd931f 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -1753,16 +1753,13 @@ void QNetworkAccessManager::setTransferTimeout(int timeout)
d_func()->transferTimeout = timeout;
}
-void QNetworkAccessManagerPrivate::_q_replyFinished()
+void QNetworkAccessManagerPrivate::_q_replyFinished(QNetworkReply *reply)
{
Q_Q(QNetworkAccessManager);
- QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
- if (reply) {
- emit q->finished(reply);
- if (reply->request().attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false).toBool())
- QMetaObject::invokeMethod(reply, [reply] { reply->deleteLater(); }, Qt::QueuedConnection);
- }
+ emit q->finished(reply);
+ if (reply->request().attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, false).toBool())
+ QMetaObject::invokeMethod(reply, [reply] { reply->deleteLater(); }, Qt::QueuedConnection);
#ifndef QT_NO_BEARERMANAGEMENT
// If there are no active requests, release our reference to the network session.
@@ -1774,13 +1771,11 @@ void QNetworkAccessManagerPrivate::_q_replyFinished()
#endif
}
-void QNetworkAccessManagerPrivate::_q_replyEncrypted()
+void QNetworkAccessManagerPrivate::_q_replyEncrypted(QNetworkReply *reply)
{
#ifndef QT_NO_SSL
Q_Q(QNetworkAccessManager);
- QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
- if (reply)
- emit q->encrypted(reply);
+ emit q->encrypted(reply);
#endif
}
@@ -1812,11 +1807,13 @@ QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply)
{
Q_Q(QNetworkAccessManager);
QNetworkReplyPrivate::setManager(reply, q);
- q->connect(reply, SIGNAL(finished()), SLOT(_q_replyFinished()));
+ q->connect(reply, &QNetworkReply::finished, reply,
+ [this, reply]() { _q_replyFinished(reply); });
#ifndef QT_NO_SSL
/* In case we're compiled without SSL support, we don't have this signal and we need to
* avoid getting a connection error. */
- q->connect(reply, SIGNAL(encrypted()), SLOT(_q_replyEncrypted()));
+ q->connect(reply, &QNetworkReply::encrypted, reply,
+ [this, reply]() { _q_replyEncrypted(reply); });
q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>)));
q->connect(reply, SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), SLOT(_q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)));
#endif
diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h
index aa4765a043..931602bbf4 100644
--- a/src/network/access/qnetworkaccessmanager.h
+++ b/src/network/access/qnetworkaccessmanager.h
@@ -208,8 +208,6 @@ private:
friend class QNetworkReplyWasmImpl;
#endif
Q_DECLARE_PRIVATE(QNetworkAccessManager)
- Q_PRIVATE_SLOT(d_func(), void _q_replyFinished())
- Q_PRIVATE_SLOT(d_func(), void _q_replyEncrypted())
Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
#ifndef QT_NO_BEARERMANAGEMENT
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
index d558f61eed..da92cad704 100644
--- a/src/network/access/qnetworkaccessmanager_p.h
+++ b/src/network/access/qnetworkaccessmanager_p.h
@@ -120,8 +120,8 @@ public:
QThread * createThread();
void destroyThread();
- void _q_replyFinished();
- void _q_replyEncrypted();
+ void _q_replyFinished(QNetworkReply *reply);
+ void _q_replyEncrypted(QNetworkReply *reply);
void _q_replySslErrors(const QList<QSslError> &errors);
void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator);
QNetworkReply *postProcess(QNetworkReply *reply);