From 06e27b6ef9549b08e34f016375bcc44a901a9325 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 1 Mar 2016 14:12:31 +0300 Subject: QtNetwork: optimize if-else conditions. De-duplicate calls by caching results. Reorder conditions: call cheap methods first. Change-Id: I27715b935247c6c21bd02f9cc40655d3f9371264 Reviewed-by: Marc Mutz --- src/network/access/qnetworkaccessbackend.cpp | 14 +++++--------- src/network/access/qnetworkcookiejar.cpp | 3 ++- src/network/access/qnetworkreplyfileimpl.cpp | 5 +++-- 3 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src/network/access') diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index c2914117db..9c223dd32f 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -385,15 +385,11 @@ bool QNetworkAccessBackend::start() // Session not ready, but can skip for loopback connections // This is not ideal. - const QString host = reply->url.host(); - - if (host == QLatin1String("localhost") || - QHostAddress(host).isLoopback() || - reply->url.isLocalFile()) { - // Don't need an open session for localhost access. - } else { - // need to wait for session to be opened - return false; + // Don't need an open session for localhost access. + if (!reply->url.isLocalFile()) { + const QString host = reply->url.host(); + if (host != QLatin1String("localhost") && !QHostAddress(host).isLoopback()) + return false; // need to wait for session to be opened } } } diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp index 1ae49aeee9..412b8d859d 100644 --- a/src/network/access/qnetworkcookiejar.cpp +++ b/src/network/access/qnetworkcookiejar.cpp @@ -331,7 +331,8 @@ bool QNetworkCookieJar::deleteCookie(const QNetworkCookie &cookie) bool QNetworkCookieJar::validateCookie(const QNetworkCookie &cookie, const QUrl &url) const { QString domain = cookie.domain(); - if (!(isParentDomain(domain, url.host()) || isParentDomain(url.host(), domain))) + const QString host = url.host(); + if (!isParentDomain(domain, host) && !isParentDomain(host, domain)) return false; // not accepted // the check for effective TLDs makes the "embedded dot" rule from RFC 2109 section 4.3.2 diff --git a/src/network/access/qnetworkreplyfileimpl.cpp b/src/network/access/qnetworkreplyfileimpl.cpp index bd89659689..36bc4b41df 100644 --- a/src/network/access/qnetworkreplyfileimpl.cpp +++ b/src/network/access/qnetworkreplyfileimpl.cpp @@ -88,11 +88,12 @@ QNetworkReplyFileImpl::QNetworkReplyFileImpl(QObject *parent, const QNetworkRequ QString fileName = url.toLocalFile(); if (fileName.isEmpty()) { - if (url.scheme() == QLatin1String("qrc")) { + const QString scheme = url.scheme(); + if (scheme == QLatin1String("qrc")) { fileName = QLatin1Char(':') + url.path(); } else { #if defined(Q_OS_ANDROID) - if (url.scheme() == QLatin1String("assets")) + if (scheme == QLatin1String("assets")) fileName = QLatin1String("assets:") + url.path(); else #endif -- cgit v1.2.3