diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-11-12 10:16:22 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-11-29 22:59:17 +0000 |
commit | 51089a5742a79467221b5781cb35a8cea023febf (patch) | |
tree | 95f765fa452cdfaa12f986e4d228d9a958c95100 /src/network | |
parent | 14d189f7875b7def6f9745bfd20527a0fce19a44 (diff) |
Use Q_UNLIKELY for every qFatal()/qCritical()
If, after checking a condition, we issue a qFatal()
or a qCritical(), by definition that check is
unlikely to be true.
Tell the compiler so it can move the error handling
code out of the normal code path to increase the
effective icache size.
Moved conditional code around where possible so that
we could always use Q_UNLIKELY, instead of having to
revert to Q_LIKELY here and there.
In some cases, simplified the expressions newly wrapped
in Q_UNLIKELY as a drive-by.
Change-Id: I67537d62b04bc6977d69254690c5ebbdf98bfd6d
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 2 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyimpl.cpp | 6 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index c4cb8e65c0..bb1580044f 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -263,7 +263,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) request.setContentLength(uploadByteDevice->size()); } else if (request.contentLength() != -1 && uploadByteDevice->size() == -1) { // everything OK, the user supplied us the contentLength - } else if (request.contentLength() == -1 && uploadByteDevice->size() == -1) { + } else if (Q_UNLIKELY(request.contentLength() == -1 && uploadByteDevice->size() == -1)) { qFatal("QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given"); } } diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 2c31afc225..05457decc4 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -993,7 +993,7 @@ void QNetworkReplyHttpImplPrivate::initCacheSaveDevice() q->connect(cacheSaveDevice, SIGNAL(aboutToClose()), SLOT(_q_cacheSaveDeviceAboutToClose())); if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) { - if (cacheSaveDevice && !cacheSaveDevice->isOpen()) + if (Q_UNLIKELY(cacheSaveDevice && !cacheSaveDevice->isOpen())) qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", managerPrivate->networkCache->metaObject()->className()); @@ -2216,7 +2216,7 @@ void QNetworkReplyHttpImplPrivate::setCachingEnabled(bool enable) return; // nothing to do either! if (enable) { - if (bytesDownloaded) { + if (Q_UNLIKELY(bytesDownloaded)) { qDebug() << "setCachingEnabled: " << bytesDownloaded << " bytesDownloaded"; // refuse to enable in this case qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written"); diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 3df39c9bdc..12ecad5ff7 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -515,7 +515,7 @@ void QNetworkReplyImplPrivate::setCachingEnabled(bool enable) return; // nothing to do either! if (enable) { - if (bytesDownloaded) { + if (Q_UNLIKELY(bytesDownloaded)) { // refuse to enable in this case qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written"); return; @@ -604,7 +604,7 @@ void QNetworkReplyImplPrivate::initCacheSaveDevice() cacheSaveDevice = networkCache()->prepare(metaData); if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) { - if (cacheSaveDevice && !cacheSaveDevice->isOpen()) + if (Q_UNLIKELY(cacheSaveDevice && !cacheSaveDevice->isOpen())) qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", networkCache()->metaObject()->className()); @@ -678,7 +678,7 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QIODevice *data) return; // read until EOF from data - if (copyDevice) { + if (Q_UNLIKELY(copyDevice)) { qCritical("QNetworkReplyImpl: copy from QIODevice already in progress -- " "backend probly needs to be fixed"); return; |