From ed9f8a0e9d2984b0b9d6aa31ab3a7209bae1708e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 1 Sep 2016 15:17:27 +0200 Subject: bearer plugins: eradicate Java-style iterators and Q_FOREACH This is the simple part of the job, removing Q_FOREACH loops which are obviously safe to be replaced by C++11 range-for. In QNetworkManagerEngine::sessionStateForId(), instead of iterating over QHash::keys(), iterate over the QHash directly (using C++11 range-for, as we're only using the values, not the keys). In QNetworkManagerEngine::connectToId(), simplify the loop body by merging three identical if blocks into one. Saves ~1.7KiB accumulated over the three Linux bearer plugins: connman, generic, nm (optimized GCC 6.1 Linux AMD64 build). Change-Id: Ic66139c25f7e2173f5a919927e269b873334d2c8 Reviewed-by: Lorn Potter --- src/plugins/bearer/linux_common/qofonoservice_linux.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/plugins/bearer/linux_common') diff --git a/src/plugins/bearer/linux_common/qofonoservice_linux.cpp b/src/plugins/bearer/linux_common/qofonoservice_linux.cpp index b0f5f29f6c..adf7feef2e 100644 --- a/src/plugins/bearer/linux_common/qofonoservice_linux.cpp +++ b/src/plugins/bearer/linux_common/qofonoservice_linux.cpp @@ -103,9 +103,9 @@ QStringList QOfonoManagerInterface::getModems() QDBusPendingReply reply = callWithArgumentList(QDBus::Block, QLatin1String("GetModems"), argumentList); reply.waitForFinished(); if (!reply.isError()) { - foreach (const ObjectPathProperties &modem, reply.value()) { + const auto modems = reply.value(); + for (const ObjectPathProperties &modem : modems) modemList << modem.path.path(); - } } } @@ -114,8 +114,8 @@ QStringList QOfonoManagerInterface::getModems() QString QOfonoManagerInterface::currentModem() { - QStringList modems = getModems(); - foreach (const QString &modem, modems) { + const QStringList modems = getModems(); + for (const QString &modem : modems) { QOfonoModemInterface device(modem); if (device.isPowered() && device.isOnline() && device.interfaces().contains(QStringLiteral("org.ofono.NetworkRegistration"))) @@ -266,9 +266,9 @@ QStringList QOfonoDataConnectionManagerInterface::contexts() QDBusPendingReply reply = call(QLatin1String("GetContexts")); reply.waitForFinished(); if (!reply.isError()) { - foreach (const ObjectPathProperties &context, reply.value()) { + const auto contexts = reply.value(); + for (const ObjectPathProperties &context : contexts) contextList << context.path.path(); - } } } return contextList; -- cgit v1.2.3