QtNetwork: eradicate Q_FOREACH loops [rvalues]
... by replacing them with C++11 range-for loops. This is the simplest of the patch series: Q_FOREACH took a copy, so we do, too. Except we don't, since we're just catching the return value that comes out of the function (RVO). We can't feed the rvalues into range-for, because they are non-const and would thus detach. Change-Id: I42c9c44d948ab1512a69d42890187bc3cf2d7e58 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
347832d759
commit
f3af7fce4a
@ -1148,7 +1148,8 @@ void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(const QHostInfo &info)
|
||||
if (networkLayerState == IPv4 || networkLayerState == IPv6 || networkLayerState == IPv4or6)
|
||||
return;
|
||||
|
||||
foreach (const QHostAddress &address, info.addresses()) {
|
||||
const auto addresses = info.addresses();
|
||||
for (const QHostAddress &address : addresses) {
|
||||
const QAbstractSocket::NetworkLayerProtocol protocol = address.protocol();
|
||||
if (protocol == QAbstractSocket::IPv4Protocol) {
|
||||
if (!foundAddress) {
|
||||
|
@ -121,7 +121,8 @@ void QNetworkAccessFtpBackend::open()
|
||||
{
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
QNetworkProxy proxy;
|
||||
foreach (const QNetworkProxy &p, proxyList()) {
|
||||
const auto proxies = proxyList();
|
||||
for (const QNetworkProxy &p : proxies) {
|
||||
// use the first FTP proxy
|
||||
// or no proxy at all
|
||||
if (p.type() == QNetworkProxy::FtpCachingProxy
|
||||
|
@ -189,7 +189,8 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData)
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach (const QNetworkCacheMetaData::RawHeader &header, metaData.rawHeaders()) {
|
||||
const auto headers = metaData.rawHeaders();
|
||||
for (const auto &header : headers) {
|
||||
if (header.first.toLower() == "content-length") {
|
||||
const qint64 size = header.second.toLongLong();
|
||||
if (size > (maximumCacheSize() * 3)/4)
|
||||
@ -639,7 +640,8 @@ bool QCacheItem::canCompress() const
|
||||
{
|
||||
bool sizeOk = false;
|
||||
bool typeOk = false;
|
||||
foreach (const QNetworkCacheMetaData::RawHeader &header, metaData.rawHeaders()) {
|
||||
const auto headers = metaData.rawHeaders();
|
||||
for (const auto &header : headers) {
|
||||
if (header.first.toLower() == "content-length") {
|
||||
qint64 size = header.second.toLongLong();
|
||||
if (size > MAX_COMPRESSION_SIZE)
|
||||
|
@ -648,7 +648,8 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq
|
||||
QNetworkProxy transparentProxy, cacheProxy;
|
||||
|
||||
// FIXME the proxy stuff should be done in the HTTP thread
|
||||
foreach (const QNetworkProxy &p, managerPrivate->queryProxy(QNetworkProxyQuery(newHttpRequest.url()))) {
|
||||
const auto proxies = managerPrivate->queryProxy(QNetworkProxyQuery(newHttpRequest.url()));
|
||||
for (const QNetworkProxy &p : proxies) {
|
||||
// use the first proxy that works
|
||||
// for non-encrypted connections, any transparent or HTTP proxy
|
||||
// for encrypted, only transparent proxies
|
||||
|
@ -365,7 +365,8 @@ QNetworkReplyNSURLConnectionImpl::QNetworkReplyNSURLConnectionImpl(QObject *pare
|
||||
cachePolicy:NSURLRequestUseProtocolCachePolicy
|
||||
timeoutInterval:60.0];
|
||||
// copy headers
|
||||
foreach (const QByteArray &header, request.rawHeaderList()) {
|
||||
const auto headers = request.rawHeaderList();
|
||||
for (const QByteArray &header : headers) {
|
||||
QByteArray headerValue = request.rawHeader(header);
|
||||
[nsRequest addValue:QString::fromUtf8(headerValue).toNSString()
|
||||
forHTTPHeaderField:QString::fromUtf8(header).toNSString()];
|
||||
|
@ -249,7 +249,8 @@ QNetworkSession::QNetworkSession(const QNetworkConfiguration &connectionConfig,
|
||||
{
|
||||
// invalid configuration
|
||||
if (!connectionConfig.identifier().isEmpty()) {
|
||||
foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->engines()) {
|
||||
const auto engines = qNetworkConfigurationManagerPrivate()->engines();
|
||||
for (QBearerEngine *engine : engines) {
|
||||
if (engine->hasIdentifier(connectionConfig.identifier())) {
|
||||
d = engine->createSessionBackend();
|
||||
d->q = this;
|
||||
|
@ -75,7 +75,8 @@ void MyObject::handleServers()
|
||||
}
|
||||
|
||||
// Handle the results.
|
||||
foreach (const QDnsServiceRecord &record, dns->serviceRecords()) {
|
||||
const auto records = dns->serviceRecords();
|
||||
for (const QDnsServiceRecord &record : records) {
|
||||
...
|
||||
}
|
||||
dns->deleteLater();
|
||||
|
@ -78,7 +78,8 @@ void MyWidget::lookedUp(const QHostInfo &host)
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (const QHostAddress &address, host.addresses())
|
||||
const auto addresses = host.addresses();
|
||||
for (const QHostAddress &address : addresses)
|
||||
qDebug() << "Found address:" << address.toString();
|
||||
}
|
||||
//! [3]
|
||||
|
@ -49,9 +49,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
//! [0]
|
||||
foreach (const QSslCertificate &cert, QSslCertificate::fromPath("C:/ssl/certificate.*.pem",
|
||||
QSsl::Pem,
|
||||
QRegExp::Wildcard)) {
|
||||
const auto certs = QSslCertificate::fromPath("C:/ssl/certificate.*.pem",
|
||||
QSsl::Pem, QRegExp::Wildcard);
|
||||
for (const QSslCertificate &cert : certs) {
|
||||
qDebug() << cert.issuerInfo(QSslCertificate::Organization);
|
||||
}
|
||||
//! [0]
|
||||
|
@ -200,8 +200,10 @@ static bool isBypassed(const QString &host, const QStringList &bypassList)
|
||||
return true;
|
||||
if (isIpAddress) {
|
||||
//exclude all local subnets
|
||||
foreach (const QNetworkInterface &iface, QNetworkInterface::allInterfaces()) {
|
||||
foreach (const QNetworkAddressEntry netaddr, iface.addressEntries()) {
|
||||
const auto ifaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &iface : ifaces) {
|
||||
const auto netaddrs = iface.addressEntries();
|
||||
for (const QNetworkAddressEntry &netaddr : netaddrs) {
|
||||
if (ipAddress.isInSubnet(netaddr.ip(), netaddr.prefixLength())) {
|
||||
return true;
|
||||
}
|
||||
|
@ -999,9 +999,11 @@ void QAbstractSocketPrivate::_q_startConnecting(const QHostInfo &hostInfo)
|
||||
if (preferredNetworkLayerProtocol == QAbstractSocket::UnknownNetworkLayerProtocol || preferredNetworkLayerProtocol == QAbstractSocket::AnyIPProtocol) {
|
||||
addresses = hostInfo.addresses();
|
||||
} else {
|
||||
foreach (const QHostAddress &address, hostInfo.addresses())
|
||||
const auto candidates = hostInfo.addresses();
|
||||
for (const QHostAddress &address : candidates) {
|
||||
if (address.protocol() == preferredNetworkLayerProtocol)
|
||||
addresses += address;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -497,9 +497,9 @@ void QHttpSocketEngine::slotSocketConnected()
|
||||
data += "Host: " + peerAddress + "\r\n";
|
||||
if (!d->proxy.hasRawHeader("User-Agent"))
|
||||
data += "User-Agent: Mozilla/5.0\r\n";
|
||||
foreach (const QByteArray &header, d->proxy.rawHeaderList()) {
|
||||
const auto headers = d->proxy.rawHeaderList();
|
||||
for (const QByteArray &header : headers)
|
||||
data += header + ": " + d->proxy.rawHeader(header) + "\r\n";
|
||||
}
|
||||
QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
|
||||
//qDebug() << "slotSocketConnected: priv=" << priv << (priv ? (int)priv->method : -1);
|
||||
if (priv && priv->method != QAuthenticatorPrivate::None) {
|
||||
|
@ -451,7 +451,8 @@ bool QSslCertificatePrivate::parseExtension(const QByteArray &data, QSslCertific
|
||||
if (!val.read(valElem.value()) || val.type() != QAsn1Element::SequenceType)
|
||||
return false;
|
||||
QVariantMap result;
|
||||
foreach (const QAsn1Element &el, val.toVector()) {
|
||||
const auto elems = val.toVector();
|
||||
for (const QAsn1Element &el : elems) {
|
||||
QVector<QAsn1Element> items = el.toVector();
|
||||
if (items.size() != 2)
|
||||
return false;
|
||||
@ -495,7 +496,8 @@ bool QSslCertificatePrivate::parseExtension(const QByteArray &data, QSslCertific
|
||||
if (!val.read(valElem.value()) || val.type() != QAsn1Element::SequenceType)
|
||||
return false;
|
||||
QVariantMap result;
|
||||
foreach (const QAsn1Element &el, val.toVector()) {
|
||||
const auto elems = val.toVector();
|
||||
for (const QAsn1Element &el : elems) {
|
||||
if (el.type() == 0x80) {
|
||||
result[QStringLiteral("keyid")] = el.value().toHex();
|
||||
} else if (el.type() == 0x82) {
|
||||
|
@ -90,7 +90,8 @@ QSslCipher::QSslCipher()
|
||||
QSslCipher::QSslCipher(const QString &name)
|
||||
: d(new QSslCipherPrivate)
|
||||
{
|
||||
foreach (const QSslCipher &cipher, QSslConfiguration::supportedCiphers()) {
|
||||
const auto ciphers = QSslConfiguration::supportedCiphers();
|
||||
for (const QSslCipher &cipher : ciphers) {
|
||||
if (cipher.name() == name) {
|
||||
*this = cipher;
|
||||
return;
|
||||
@ -111,7 +112,8 @@ QSslCipher::QSslCipher(const QString &name)
|
||||
QSslCipher::QSslCipher(const QString &name, QSsl::SslProtocol protocol)
|
||||
: d(new QSslCipherPrivate)
|
||||
{
|
||||
foreach (const QSslCipher &cipher, QSslConfiguration::supportedCiphers()) {
|
||||
const auto ciphers = QSslConfiguration::supportedCiphers();
|
||||
for (const QSslCipher &cipher : ciphers) {
|
||||
if (cipher.name() == name && cipher.protocol() == protocol) {
|
||||
*this = cipher;
|
||||
return;
|
||||
|
@ -224,7 +224,8 @@ init_context:
|
||||
const QDateTime now = QDateTime::currentDateTimeUtc();
|
||||
|
||||
// Add all our CAs to this store.
|
||||
foreach (const QSslCertificate &caCertificate, sslContext->sslConfiguration.caCertificates()) {
|
||||
const auto caCertificates = sslContext->sslConfiguration.caCertificates();
|
||||
for (const QSslCertificate &caCertificate : caCertificates) {
|
||||
// From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
|
||||
//
|
||||
// If several CA certificates matching the name, key identifier, and
|
||||
|
@ -1249,7 +1249,8 @@ void QSslSocket::setCiphers(const QString &ciphers)
|
||||
{
|
||||
Q_D(QSslSocket);
|
||||
d->configuration.ciphers.clear();
|
||||
foreach (const QString &cipherName, ciphers.split(QLatin1Char(':'), QString::SkipEmptyParts)) {
|
||||
const auto cipherNames = ciphers.split(QLatin1Char(':'), QString::SkipEmptyParts);
|
||||
for (const QString &cipherName : cipherNames) {
|
||||
QSslCipher cipher(cipherName);
|
||||
if (!cipher.isNull())
|
||||
d->configuration.ciphers << cipher;
|
||||
|
@ -286,7 +286,8 @@ int q_X509Callback(int ok, X509_STORE_CTX *ctx)
|
||||
qCDebug(lcSsl) << "verification error: dumping bad certificate";
|
||||
qCDebug(lcSsl) << QSslCertificatePrivate::QSslCertificate_from_X509(q_X509_STORE_CTX_get_current_cert(ctx)).toPem();
|
||||
qCDebug(lcSsl) << "dumping chain";
|
||||
foreach (QSslCertificate cert, QSslSocketBackendPrivate::STACKOFX509_to_QSslCertificates(q_X509_STORE_CTX_get_chain(ctx))) {
|
||||
const auto certs = QSslSocketBackendPrivate::STACKOFX509_to_QSslCertificates(q_X509_STORE_CTX_get_chain(ctx));
|
||||
for (const QSslCertificate &cert : certs) {
|
||||
qCDebug(lcSsl) << "Issuer:" << "O=" << cert.issuerInfo(QSslCertificate::Organization)
|
||||
<< "CN=" << cert.issuerInfo(QSslCertificate::CommonName)
|
||||
<< "L=" << cert.issuerInfo(QSslCertificate::LocalityName)
|
||||
@ -1625,7 +1626,8 @@ QList<QSslError> QSslSocketBackendPrivate::verify(const QList<QSslCertificate> &
|
||||
}
|
||||
|
||||
const QDateTime now = QDateTime::currentDateTimeUtc();
|
||||
foreach (const QSslCertificate &caCertificate, QSslConfiguration::defaultConfiguration().caCertificates()) {
|
||||
const auto caCertificates = QSslConfiguration::defaultConfiguration().caCertificates();
|
||||
for (const QSslCertificate &caCertificate : caCertificates) {
|
||||
// From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
|
||||
//
|
||||
// If several CA certificates matching the name, key identifier, and
|
||||
|
Loading…
Reference in New Issue
Block a user