diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-01-26 14:38:54 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-04-25 07:38:50 +0000 |
commit | 036b40403260c4b5de256e8118a90ec04538a312 (patch) | |
tree | 87f81334e76f82c080c3168534e13293f50ed2bb /src/network | |
parent | a1dec825f9aa9d7f86d740fd420f1c084463f507 (diff) | |
download | qtbase-036b40403260c4b5de256e8118a90ec04538a312.tar.gz |
QtNetwork: eradicate Q_FOREACH loops [already const]
... (or trivially marked const) local variables or
parameters, by replacing them with C++11 range-for
loops.
Also ported one indexed loop.
Change-Id: Idddcac48ce7527b1ea674671ceb9aaf4d31fb42e
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkcookiejar.cpp | 2 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkrequest.cpp | 4 | ||||
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager_p.cpp | 17 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface.cpp | 12 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy_generic.cpp | 2 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy_libproxy.cpp | 4 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy_win.cpp | 8 | ||||
-rw-r--r-- | src/network/ssl/qsslcontext_openssl.cpp | 6 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_openssl.cpp | 2 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_openssl_symbols.cpp | 12 | ||||
-rw-r--r-- | src/network/ssl/qsslsocket_winrt.cpp | 4 |
13 files changed, 40 insertions, 41 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 69687b5ab8..c70d15f8c4 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -520,8 +520,8 @@ QUrl QHttpNetworkConnectionPrivate::parseRedirectResponse(QAbstractSocket *socke return QUrl(); QUrl rUrl; - QList<QPair<QByteArray, QByteArray> > fields = reply->header(); - foreach (const QNetworkReply::RawHeaderPair &header, fields) { + const QList<QPair<QByteArray, QByteArray> > fields = reply->header(); + for (const QNetworkReply::RawHeaderPair &header : fields) { if (header.first.toLower() == "location") { rUrl = QUrl::fromEncoded(header.second); break; diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp index 398895e92f..283dd3509e 100644 --- a/src/network/access/qnetworkcookiejar.cpp +++ b/src/network/access/qnetworkcookiejar.cpp @@ -188,7 +188,7 @@ bool QNetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieLis const QUrl &url) { bool added = false; - foreach (QNetworkCookie cookie, cookieList) { + for (QNetworkCookie cookie : cookieList) { cookie.normalize(url); if (validateCookie(cookie, url) && insertCookie(cookie)) added = true; diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index e1323527f6..32181bfd59 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1512,8 +1512,8 @@ QNetworkCacheMetaData QNetworkReplyHttpImplPrivate::fetchCacheMetaData(const QNe cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; - QList<QByteArray> newHeaders = q->rawHeaderList(); - foreach (QByteArray header, newHeaders) { + const QList<QByteArray> newHeaders = q->rawHeaderList(); + for (QByteArray header : newHeaders) { QByteArray originalHeader = header; header = header.toLower(); bool hop_by_hop = diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 2ee85fd049..d1c2ff9f53 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -857,8 +857,8 @@ static QVariant parseHttpDate(const QByteArray &raw) static QVariant parseCookieHeader(const QByteArray &raw) { QList<QNetworkCookie> result; - QList<QByteArray> cookieList = raw.split(';'); - foreach (const QByteArray &cookie, cookieList) { + const QList<QByteArray> cookieList = raw.split(';'); + for (const QByteArray &cookie : cookieList) { QList<QNetworkCookie> parsed = QNetworkCookie::parseCookies(cookie.trimmed()); if (parsed.count() != 1) return QVariant(); // invalid Cookie: header diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index f2a79319a1..e9bf99628c 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -100,7 +100,7 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( { QMutexLocker locker(&mutex); - foreach (QBearerEngine *engine, sessionEngines) { + for (QBearerEngine *engine : sessionEngines) { QNetworkConfigurationPrivatePointer ptr = engine->defaultConfiguration(); if (ptr) { QNetworkConfiguration config; @@ -114,7 +114,7 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( // Return first active snap QNetworkConfigurationPrivatePointer defaultConfiguration; - foreach (QBearerEngine *engine, sessionEngines) { + for (QBearerEngine *engine : sessionEngines) { QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it; QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end; @@ -156,7 +156,7 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( 6. Discovered Other */ - foreach (QBearerEngine *engine, sessionEngines) { + for (QBearerEngine *engine : sessionEngines) { QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it; QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end; @@ -219,7 +219,7 @@ QList<QNetworkConfiguration> QNetworkConfigurationManagerPrivate::allConfigurati QMutexLocker locker(&mutex); - foreach (QBearerEngine *engine, sessionEngines) { + for (QBearerEngine *engine : sessionEngines) { QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it; QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end; @@ -263,7 +263,7 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::configurationFromIden QMutexLocker locker(&mutex); - foreach (QBearerEngine *engine, sessionEngines) { + for (QBearerEngine *engine : sessionEngines) { QMutexLocker locker(&engine->mutex); if (auto ptr = engine->accessPointConfigurations.value(identifier)) { item.d = std::move(ptr); @@ -297,7 +297,7 @@ QNetworkConfigurationManager::Capabilities QNetworkConfigurationManagerPrivate:: QNetworkConfigurationManager::Capabilities capFlags; - foreach (QBearerEngine *engine, sessionEngines) + for (QBearerEngine *engine : sessionEngines) capFlags |= engine->capabilities(); return capFlags; @@ -442,11 +442,10 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (firstUpdate) { firstUpdate = false; - QList<QBearerEngine*> enginesToInitialize = sessionEngines; //shallow copy the list in case it is modified when we unlock mutex + const QList<QBearerEngine*> enginesToInitialize = sessionEngines; //shallow copy the list in case it is modified when we unlock mutex locker.unlock(); - foreach (QBearerEngine* engine, enginesToInitialize) { + for (QBearerEngine* engine : enginesToInitialize) QMetaObject::invokeMethod(engine, "initialize", Qt::BlockingQueuedConnection); - } } } diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp index e55e113619..8c3467a1e3 100644 --- a/src/network/kernel/qnetworkinterface.cpp +++ b/src/network/kernel/qnetworkinterface.cpp @@ -120,11 +120,11 @@ QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interface QList<QSharedDataPointer<QNetworkInterfacePrivate> > QNetworkInterfaceManager::allInterfaces() { - QList<QNetworkInterfacePrivate *> list = postProcess(scan()); + const QList<QNetworkInterfacePrivate *> list = postProcess(scan()); QList<QSharedDataPointer<QNetworkInterfacePrivate> > result; result.reserve(list.size()); - foreach (QNetworkInterfacePrivate *ptr, list) + for (QNetworkInterfacePrivate *ptr : list) result << QSharedDataPointer<QNetworkInterfacePrivate>(ptr); return result; @@ -611,10 +611,10 @@ QString QNetworkInterface::interfaceNameFromIndex(int index) */ QList<QNetworkInterface> QNetworkInterface::allInterfaces() { - QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces(); + const QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces(); QList<QNetworkInterface> result; result.reserve(privs.size()); - foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) { + for (const auto &p : privs) { QNetworkInterface item; item.d = p; result << item; @@ -631,9 +631,9 @@ QList<QNetworkInterface> QNetworkInterface::allInterfaces() */ QList<QHostAddress> QNetworkInterface::allAddresses() { - QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces(); + const QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces(); QList<QHostAddress> result; - foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) { + for (const auto &p : privs) { foreach (const QNetworkAddressEntry &entry, p->addressEntries) result += entry.ip(); } diff --git a/src/network/kernel/qnetworkproxy_generic.cpp b/src/network/kernel/qnetworkproxy_generic.cpp index db1083f3e0..e69870a98c 100644 --- a/src/network/kernel/qnetworkproxy_generic.cpp +++ b/src/network/kernel/qnetworkproxy_generic.cpp @@ -59,7 +59,7 @@ static bool ignoreProxyFor(const QNetworkProxyQuery &query) const QList<QByteArray> noProxyTokens = noProxy.split(','); - foreach (const QByteArray &rawToken, noProxyTokens) { + for (const QByteArray &rawToken : noProxyTokens) { QByteArray token = rawToken.trimmed(); QString peerHostName = query.peerHostName(); diff --git a/src/network/kernel/qnetworkproxy_libproxy.cpp b/src/network/kernel/qnetworkproxy_libproxy.cpp index e89df79226..184dc6469d 100644 --- a/src/network/kernel/qnetworkproxy_libproxy.cpp +++ b/src/network/kernel/qnetworkproxy_libproxy.cpp @@ -122,10 +122,10 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro return proxyList; } - QList<QUrl> rawProxies = libProxyWrapper()->getProxies(queryUrl); + const QList<QUrl> rawProxies = libProxyWrapper()->getProxies(queryUrl); bool haveDirectConnection = false; - foreach (const QUrl& url, rawProxies) { + for (const QUrl& url : rawProxies) { QNetworkProxy::ProxyType type; const QString scheme = url.scheme(); if (scheme == QLatin1String("http")) { diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp index fe9f088062..0838227123 100644 --- a/src/network/kernel/qnetworkproxy_win.cpp +++ b/src/network/kernel/qnetworkproxy_win.cpp @@ -194,7 +194,7 @@ static bool isBypassed(const QString &host, const QStringList &bypassList) return true; // does it match the list of exclusions? - foreach (const QString &entry, bypassList) { + for (const QString &entry : bypassList) { if (entry == QLatin1String("<local>")) { if (isSimple) return true; @@ -241,7 +241,7 @@ static QList<QNetworkProxy> filterProxyListByCapabilities(const QList<QNetworkPr break; } QList<QNetworkProxy> result; - foreach (const QNetworkProxy& proxy, proxyList) { + for (const QNetworkProxy &proxy : proxyList) { if (proxy.capabilities() & requiredCaps) result.append(proxy); } @@ -251,7 +251,7 @@ static QList<QNetworkProxy> filterProxyListByCapabilities(const QList<QNetworkPr static QList<QNetworkProxy> removeDuplicateProxies(const QList<QNetworkProxy> &proxyList) { QList<QNetworkProxy> result; - foreach (QNetworkProxy proxy, proxyList) { + for (const QNetworkProxy &proxy : proxyList) { bool append = true; for (int i=0; i < result.count(); i++) { if (proxy.hostName() == result.at(i).hostName() @@ -283,7 +283,7 @@ static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, con QHash<QString, QNetworkProxy> taggedProxies; const QString requiredTag = query.protocolTag(); bool checkTags = !requiredTag.isEmpty() && query.queryType() != QNetworkProxyQuery::TcpServer; //windows tags are only for clients - foreach (const QString &entry, proxyList) { + for (const QString &entry : proxyList) { int server = 0; QNetworkProxy::ProxyType proxyType = QNetworkProxy::HttpProxy; diff --git a/src/network/ssl/qsslcontext_openssl.cpp b/src/network/ssl/qsslcontext_openssl.cpp index b3786f989e..064cd45e54 100644 --- a/src/network/ssl/qsslcontext_openssl.cpp +++ b/src/network/ssl/qsslcontext_openssl.cpp @@ -243,9 +243,9 @@ init_context: if (QSslSocketPrivate::s_loadRootCertsOnDemand && allowRootCertOnDemandLoading) { // tell OpenSSL the directories where to look up the root certs on demand - QList<QByteArray> unixDirs = QSslSocketPrivate::unixRootCertDirectories(); - for (int a = 0; a < unixDirs.count(); ++a) - q_SSL_CTX_load_verify_locations(sslContext->ctx, 0, unixDirs.at(a).constData()); + const QList<QByteArray> unixDirs = QSslSocketPrivate::unixRootCertDirectories(); + for (const QByteArray &unixDir : unixDirs) + q_SSL_CTX_load_verify_locations(sslContext->ctx, 0, unixDir.constData()); } if (!sslContext->sslConfiguration.localCertificate().isNull()) { diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp index 0200f5e70b..fed179de99 100644 --- a/src/network/ssl/qsslsocket_openssl.cpp +++ b/src/network/ssl/qsslsocket_openssl.cpp @@ -1660,7 +1660,7 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> & } bool first = true; - foreach (const QSslCertificate &cert, certificateChain) { + for (const QSslCertificate &cert : certificateChain) { if (first) { first = false; continue; diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp index d0982377fb..5954ba34bd 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols.cpp +++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp @@ -549,11 +549,11 @@ static QStringList libraryPathList() Q_NEVER_INLINE static QStringList findAllLibs(QLatin1String filter) { - QStringList paths = libraryPathList(); + const QStringList paths = libraryPathList(); QStringList found; const QStringList filters((QString(filter))); - foreach (const QString &path, paths) { + for (const QString &path : paths) { QDir dir(path); QStringList entryList = dir.entryList(filters, QDir::Files); @@ -688,16 +688,16 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl() #endif // third attempt: loop on the most common library paths and find libssl - QStringList sslList = findAllLibSsl(); - QStringList cryptoList = findAllLibCrypto(); + const QStringList sslList = findAllLibSsl(); + const QStringList cryptoList = findAllLibCrypto(); - foreach (const QString &crypto, cryptoList) { + for (const QString &crypto : cryptoList) { libcrypto->setFileNameAndVersion(crypto, -1); if (libcrypto->load()) { QFileInfo fi(crypto); QString version = fi.completeSuffix(); - foreach (const QString &ssl, sslList) { + for (const QString &ssl : sslList) { if (!ssl.endsWith(version)) continue; diff --git a/src/network/ssl/qsslsocket_winrt.cpp b/src/network/ssl/qsslsocket_winrt.cpp index 045c89eb0e..bce7c28d2c 100644 --- a/src/network/ssl/qsslsocket_winrt.cpp +++ b/src/network/ssl/qsslsocket_winrt.cpp @@ -105,7 +105,7 @@ struct SslSocketGlobal void syncCaCertificates(const QSet<QSslCertificate> &add, const QSet<QSslCertificate> &remove) { QMutexLocker locker(&certificateMutex); - foreach (const QSslCertificate &certificate, add) { + for (const QSslCertificate &certificate : add) { QHash<QSslCertificate, QAtomicInt>::iterator it = additionalCertificates.find(certificate); if (it != additionalCertificates.end()) { it.value().ref(); // Add a reference @@ -117,7 +117,7 @@ struct SslSocketGlobal additionalCertificates.insert(certificate, 1); } } - foreach (const QSslCertificate &certificate, remove) { + for (const QSslCertificate &certificate : remove) { QHash<QSslCertificate, QAtomicInt>::iterator it = additionalCertificates.find(certificate); if (it != additionalCertificates.end() && !it.value().deref()) { // no more references, remove certificate |