summaryrefslogtreecommitdiffstats
path: root/src/plugins/bearer/connman
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-09-01 15:17:27 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-09-02 12:46:41 +0000
commited9f8a0e9d2984b0b9d6aa31ab3a7209bae1708e (patch)
treec0f7b12c7a5e2a0f78823eb53bbd7391280a061a /src/plugins/bearer/connman
parent73331eebf885ba8918447d26ba37bef2208bdb5e (diff)
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 <lorn.potter@canonical.com>
Diffstat (limited to 'src/plugins/bearer/connman')
-rw-r--r--src/plugins/bearer/connman/qconnmanengine.cpp16
-rw-r--r--src/plugins/bearer/connman/qconnmanservice_linux.cpp14
2 files changed, 16 insertions, 14 deletions
diff --git a/src/plugins/bearer/connman/qconnmanengine.cpp b/src/plugins/bearer/connman/qconnmanengine.cpp
index 51ee51a64a..eabae5a07b 100644
--- a/src/plugins/bearer/connman/qconnmanengine.cpp
+++ b/src/plugins/bearer/connman/qconnmanengine.cpp
@@ -93,9 +93,9 @@ void QConnmanEngine::initialize()
connect(connmanManager,SIGNAL(servicesReady(QStringList)),this,SLOT(servicesReady(QStringList)));
connect(connmanManager,SIGNAL(scanFinished(bool)),this,SLOT(finishedScan(bool)));
- foreach (const QString &servPath, connmanManager->getServices()) {
+ const auto servPaths = connmanManager->getServices();
+ for (const QString &servPath : servPaths)
addServiceConfiguration(servPath);
- }
Q_EMIT updateCompleted();
}
@@ -115,9 +115,8 @@ void QConnmanEngine::changedModem()
void QConnmanEngine::servicesReady(const QStringList &list)
{
QMutexLocker locker(&mutex);
- foreach (const QString &servPath, list) {
+ for (const QString &servPath : list)
addServiceConfiguration(servPath);
- }
Q_EMIT updateCompleted();
}
@@ -329,7 +328,8 @@ QNetworkSessionPrivate *QConnmanEngine::createSessionBackend()
QNetworkConfigurationPrivatePointer QConnmanEngine::defaultConfiguration()
{
const QMutexLocker locker(&mutex);
- Q_FOREACH (const QString &servPath, connmanManager->getServices()) {
+ const auto servPaths = connmanManager->getServices();
+ for (const QString &servPath : servPaths) {
if (connmanServiceInterfaces.contains(servPath)) {
if (accessPointConfigurations.contains(servPath))
return accessPointConfigurations.value(servPath);
@@ -461,7 +461,8 @@ QNetworkConfiguration::BearerType QConnmanEngine::ofonoTechToBearerType(const QS
bool QConnmanEngine::isRoamingAllowed(const QString &context)
{
- foreach (const QString &dcPath, ofonoContextManager->contexts()) {
+ const auto dcPaths = ofonoContextManager->contexts();
+ for (const QString &dcPath : dcPaths) {
if (dcPath.contains(context.section("_",-1))) {
return ofonoContextManager->roamingAllowed();
}
@@ -557,7 +558,8 @@ bool QConnmanEngine::requiresPolling() const
void QConnmanEngine::reEvaluateCellular()
{
- Q_FOREACH (const QString &servicePath, connmanManager->getServices()) {
+ const auto servicePaths = connmanManager->getServices();
+ for (const QString &servicePath : servicePaths) {
if (servicePath.contains("cellular") && accessPointConfigurations.contains(servicePath)) {
configurationChange(connmanServiceInterfaces.value(servicePath));
}
diff --git a/src/plugins/bearer/connman/qconnmanservice_linux.cpp b/src/plugins/bearer/connman/qconnmanservice_linux.cpp
index 7fbbe2cd07..bc89f540fc 100644
--- a/src/plugins/bearer/connman/qconnmanservice_linux.cpp
+++ b/src/plugins/bearer/connman/qconnmanservice_linux.cpp
@@ -144,10 +144,9 @@ void QConnmanManagerInterface::servicesReply(QDBusPendingCallWatcher *call)
qDebug() << serv_reply.error().message();
} else {
servicesList.clear(); //connman list changes order
- ConnmanMap connmanobj;
- Q_FOREACH (connmanobj, serv_reply.value()) {
+ const ConnmanMapList connmanobjs = serv_reply.value();
+ for (const ConnmanMap &connmanobj : connmanobjs)
servicesList << connmanobj.objectPath.path();
- }
Q_EMIT servicesReady(servicesList);
}
call->deleteLater();
@@ -181,7 +180,7 @@ void QConnmanManagerInterface::connectNotify(const QMetaMethod &signal)
void QConnmanManagerInterface::onServicesChanged(const ConnmanMapList &changed, const QList<QDBusObjectPath> &removed)
{
servicesList.clear(); //connman list changes order
- Q_FOREACH (const ConnmanMap &connmanobj, changed) {
+ for (const ConnmanMap &connmanobj : changed) {
const QString svcPath(connmanobj.objectPath.path());
servicesList << svcPath;
}
@@ -225,7 +224,8 @@ QStringList QConnmanManagerInterface::getTechnologies()
QDBusPendingReply<ConnmanMapList> reply = call(QLatin1String("GetTechnologies"));
reply.waitForFinished();
if (!reply.isError()) {
- Q_FOREACH (const ConnmanMap &map, reply.value()) {
+ const ConnmanMapList maps = reply.value();
+ for (const ConnmanMap &map : maps) {
if (!technologiesMap.contains(map.objectPath.path())) {
technologyAdded(map.objectPath, map.propertyMap);
}
@@ -241,9 +241,9 @@ QStringList QConnmanManagerInterface::getServices()
QDBusPendingReply<ConnmanMapList> reply = call(QLatin1String("GetServices"));
reply.waitForFinished();
if (!reply.isError()) {
- Q_FOREACH (const ConnmanMap &map, reply.value()) {
+ const ConnmanMapList maps = reply.value();
+ for (const ConnmanMap &map : maps)
servicesList << map.objectPath.path();
- }
}
}
return servicesList;