QtNetwork: optimize if-else conditions.
De-duplicate calls by caching results. Reorder conditions: call cheap methods first. Change-Id: I27715b935247c6c21bd02f9cc40655d3f9371264 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
1bd24e5b0c
commit
06e27b6ef9
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -112,16 +112,17 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro
|
||||
|
||||
if (!proxy_env.isEmpty()) {
|
||||
QUrl url = QUrl(QString::fromLocal8Bit(proxy_env));
|
||||
if (url.scheme() == QLatin1String("socks5")) {
|
||||
const QString scheme = url.scheme();
|
||||
if (scheme == QLatin1String("socks5")) {
|
||||
QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(),
|
||||
url.port() ? url.port() : 1080, url.userName(), url.password());
|
||||
proxyList << proxy;
|
||||
} else if (url.scheme() == QLatin1String("socks5h")) {
|
||||
} else if (scheme == QLatin1String("socks5h")) {
|
||||
QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, url.host(),
|
||||
url.port() ? url.port() : 1080, url.userName(), url.password());
|
||||
proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability);
|
||||
proxyList << proxy;
|
||||
} else if ((url.scheme() == QLatin1String("http") || url.scheme().isEmpty())
|
||||
} else if ((scheme.isEmpty() || scheme == QLatin1String("http"))
|
||||
&& query.queryType() != QNetworkProxyQuery::UdpSocket
|
||||
&& query.queryType() != QNetworkProxyQuery::TcpServer) {
|
||||
QNetworkProxy proxy(QNetworkProxy::HttpProxy, url.host(),
|
||||
|
Loading…
Reference in New Issue
Block a user