From 4fb59e0a8d40083f545dd43a370bd6d7b7b4cd35 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 15 Feb 2010 15:18:26 +1000 Subject: Optimise iterations over QHash. --- src/network/bearer/qbearerengine.cpp | 25 ++++++++++----------- src/network/bearer/qnetworkconfigmanager.cpp | 20 ++++++++--------- src/network/bearer/qnetworkconfigmanager_p.cpp | 30 +++++++++++++++----------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp index bd2ca6c..58d64f2 100644 --- a/src/network/bearer/qbearerengine.cpp +++ b/src/network/bearer/qbearerengine.cpp @@ -50,22 +50,23 @@ QBearerEngine::QBearerEngine(QObject *parent) QBearerEngine::~QBearerEngine() { - foreach (const QString &oldIface, snapConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = snapConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); + QHash::Iterator it; + QHash::Iterator end; + for (it = snapConfigurations.begin(), end = snapConfigurations.end(); it != end; ++it) { + it.value()->isValid = false; + it.value()->id.clear(); } - foreach (const QString &oldIface, accessPointConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); + for (it = accessPointConfigurations.begin(), end = accessPointConfigurations.end(); + it != end; ++it) { + it.value()->isValid = false; + it.value()->id.clear(); } - foreach (const QString &oldIface, userChoiceConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = userChoiceConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); + for (it = userChoiceConfigurations.begin(), end = userChoiceConfigurations.end(); + it != end; ++it) { + it.value()->isValid = false; + it.value()->id.clear(); } } diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 2e37e01..f54a985 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -235,25 +235,25 @@ QList QNetworkConfigurationManager::allConfigurations(QNe QNetworkConfigurationManagerPrivate* conPriv = connManager(); foreach (QBearerEngine *engine, conPriv->sessionEngines) { - QStringList cpsIdents = engine->accessPointConfigurations.keys(); + QHash::Iterator it; + QHash::Iterator end; //find all InternetAccessPoints - foreach (const QString &ii, cpsIdents) { - QNetworkConfigurationPrivatePointer p = engine->accessPointConfigurations.value(ii); - if ((p->state & filter) == filter) { + for (it = engine->accessPointConfigurations.begin(), + end = engine->accessPointConfigurations.end(); it != end; ++it) { + if ((it.value()->state & filter) == filter) { QNetworkConfiguration pt; - pt.d = engine->accessPointConfigurations.value(ii); + pt.d = it.value(); result << pt; } } //find all service networks - cpsIdents = engine->snapConfigurations.keys(); - foreach (const QString &ii, cpsIdents) { - QNetworkConfigurationPrivatePointer p = engine->snapConfigurations.value(ii); - if ((p->state & filter) == filter) { + for (it = engine->snapConfigurations.begin(), + end = engine->snapConfigurations.end(); it != end; ++it) { + if ((it.value()->state & filter) == filter) { QNetworkConfiguration pt; - pt.d = engine->snapConfigurations.value(ii); + pt.d = it.value(); result << pt; } } diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 01a85a5..b7a30b8 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -244,16 +244,19 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( QNetworkConfigurationPrivatePointer firstDiscovered; foreach (QBearerEngine *engine, sessionEngines) { - foreach (const QString &id, engine->snapConfigurations.keys()) { - QNetworkConfigurationPrivatePointer ptr = engine->snapConfigurations.value(id); + QHash::Iterator it; + QHash::Iterator end; - if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + for (it = engine->snapConfigurations.begin(), end = engine->snapConfigurations.end(); + it != end; ++it) { + if ((it.value()->state & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active) { QNetworkConfiguration config; - config.d = ptr; + config.d = it.value(); return config; - } else if ((ptr->state & QNetworkConfiguration::Discovered) == + } else if ((it.value()->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { - firstDiscovered = ptr; + firstDiscovered = it.value(); } } } @@ -269,16 +272,19 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( firstDiscovered.reset(); foreach (QBearerEngine *engine, sessionEngines) { - foreach (const QString &id, engine->accessPointConfigurations.keys()) { - QNetworkConfigurationPrivatePointer ptr = engine->accessPointConfigurations.value(id); + QHash::Iterator it; + QHash::Iterator end; - if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + for (it = engine->accessPointConfigurations.begin(), + end = engine->accessPointConfigurations.end(); it != end; ++it) { + if ((it.value()->state & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active) { QNetworkConfiguration config; - config.d = ptr; + config.d = it.value(); return config; - } else if ((ptr->state & QNetworkConfiguration::Discovered) == + } else if ((it.value()->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { - firstDiscovered = ptr; + firstDiscovered = it.value(); } } } -- cgit v0.12