Skip to content

Commit

Permalink
QNetworkAccessManager: Avoid unnecessary calls to sender()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Morten242 committed Jan 16, 2020
1 parent bd828ba commit 6faaef5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
23 changes: 10 additions & 13 deletions src/network/access/qnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/network/access/qnetworkaccessmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ protected Q_SLOTS:
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
Expand Down
4 changes: 2 additions & 2 deletions src/network/access/qnetworkaccessmanager_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class QNetworkAccessManagerPrivate: public QObjectPrivate
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);
Expand Down

0 comments on commit 6faaef5

Please sign in to comment.