summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-02-08 14:13:51 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-02-15 12:40:08 +0000
commit0668d08b879aa7ddb7fde8a17811fc806000671b (patch)
tree7cfea73ab6e14173b46bc1fbad430eeee258026b /src
parentab8cc8387f1891ccf99721bfe5a6182c507e332f (diff)
QHttpNetworkConnectionPrivate: de-duplicate calls in if-else chains
... and loops. Every QNetworkConfiguration::bearerType() call produces lock/unlock of mutex. Fix: cache result. Every QHttpNetworkRequest::contentLength() call contains internal loop. Fix: cache result. Also cache results of QNonContiguousByteDevice::size() and QHostAddress::protocol(). Change-Id: I01124648b1972f480905433d9b3551c2246e1bde Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index 072c5c9ff5..15a886c21d 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -261,15 +261,17 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)
// check if Content-Length is provided
QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
if (uploadByteDevice) {
- if (request.contentLength() != -1 && uploadByteDevice->size() != -1) {
+ const qint64 contentLength = request.contentLength();
+ const qint64 uploadDeviceSize = uploadByteDevice->size();
+ if (contentLength != -1 && uploadDeviceSize != -1) {
// both values known, take the smaller one.
- request.setContentLength(qMin(uploadByteDevice->size(), request.contentLength()));
- } else if (request.contentLength() == -1 && uploadByteDevice->size() != -1) {
+ request.setContentLength(qMin(uploadDeviceSize, contentLength));
+ } else if (contentLength == -1 && uploadDeviceSize != -1) {
// content length not supplied by user, but the upload device knows it
- request.setContentLength(uploadByteDevice->size());
- } else if (request.contentLength() != -1 && uploadByteDevice->size() == -1) {
+ request.setContentLength(uploadDeviceSize);
+ } else if (contentLength != -1 && uploadDeviceSize == -1) {
// everything OK, the user supplied us the contentLength
- } else if (Q_UNLIKELY(request.contentLength() == -1 && uploadByteDevice->size() == -1)) {
+ } else if (Q_UNLIKELY(contentLength == -1 && uploadDeviceSize == -1)) {
qFatal("QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given");
}
}
@@ -1113,11 +1115,12 @@ void QHttpNetworkConnectionPrivate::startHostInfoLookup()
#endif
QHostAddress temp;
if (temp.setAddress(lookupHost)) {
- if (temp.protocol() == QAbstractSocket::IPv4Protocol) {
+ const QAbstractSocket::NetworkLayerProtocol protocol = temp.protocol();
+ if (protocol == QAbstractSocket::IPv4Protocol) {
networkLayerState = QHttpNetworkConnectionPrivate::IPv4;
QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection);
return;
- } else if (temp.protocol() == QAbstractSocket::IPv6Protocol) {
+ } else if (protocol == QAbstractSocket::IPv6Protocol) {
networkLayerState = QHttpNetworkConnectionPrivate::IPv6;
QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection);
return;
@@ -1146,13 +1149,14 @@ void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(const QHostInfo &info)
return;
foreach (const QHostAddress &address, info.addresses()) {
- if (address.protocol() == QAbstractSocket::IPv4Protocol) {
+ const QAbstractSocket::NetworkLayerProtocol protocol = address.protocol();
+ if (protocol == QAbstractSocket::IPv4Protocol) {
if (!foundAddress) {
foundAddress = true;
delayIpv4 = false;
}
bIpv4 = true;
- } else if (address.protocol() == QAbstractSocket::IPv6Protocol) {
+ } else if (protocol == QAbstractSocket::IPv6Protocol) {
if (!foundAddress) {
foundAddress = true;
delayIpv4 = true;
@@ -1213,13 +1217,14 @@ void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup()
int timeout = 300;
#ifndef QT_NO_BEARERMANAGEMENT
if (networkSession) {
- if (networkSession->configuration().bearerType() == QNetworkConfiguration::Bearer2G)
+ const QNetworkConfiguration::BearerType bearerType = networkSession->configuration().bearerType();
+ if (bearerType == QNetworkConfiguration::Bearer2G)
timeout = 800;
- else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerCDMA2000)
+ else if (bearerType == QNetworkConfiguration::BearerCDMA2000)
timeout = 500;
- else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerWCDMA)
+ else if (bearerType == QNetworkConfiguration::BearerWCDMA)
timeout = 500;
- else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerHSPA)
+ else if (bearerType == QNetworkConfiguration::BearerHSPA)
timeout = 400;
}
#endif