diff options
author | Anton Kudryavtsev <a.kudryavtsev@netris.ru> | 2016-01-14 16:19:41 +0300 |
---|---|---|
committer | Anton Kudryavtsev <a.kudryavtsev@netris.ru> | 2016-01-15 11:28:51 +0000 |
commit | fad740822e13225f9cd9d567a346b4f2b7d6f65a (patch) | |
tree | 63cb777b9f671ed56f130a3bae67ddd9d591bbaa /src | |
parent | a756c0a88b43c4b7251d6b2b95acddbe3af26932 (diff) |
fix expensive iteration over QMap::keys(), QHash::keys()
... and QJsonObject::keys()
Change-Id: I9a8ba44406a1e2cbdfffd266d2b5cb664f7440fc
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src')
7 files changed, 32 insertions, 33 deletions
diff --git a/src/location/maps/qgeoserviceprovider.cpp b/src/location/maps/qgeoserviceprovider.cpp index b1b9cb86..51b0de60 100644 --- a/src/location/maps/qgeoserviceprovider.cpp +++ b/src/location/maps/qgeoserviceprovider.cpp @@ -625,21 +625,20 @@ void QGeoServiceProviderPrivate::unload() /* Filter out any parameter that doesn't match any plugin */ void QGeoServiceProviderPrivate::filterParameterMap() { - const QList<QString> availablePlugins = - QGeoServiceProviderPrivate::plugins().keys(); + const auto availablePlugins = QGeoServiceProviderPrivate::plugins(); cleanedParameterMap = parameterMap; - foreach (const QString& name, availablePlugins) { - if (name == providerName) // don't remove parameters for current provider + for (auto it = availablePlugins.keyBegin(), end = availablePlugins.keyEnd(); it != end; ++it) { + if (*it == providerName) // don't remove parameters for current provider continue; QVariantMap::iterator i = cleanedParameterMap.begin(); while (i != cleanedParameterMap.end()) { // remove every parameter meant for other plugins - if (i.key().startsWith(QString(name + QLatin1Char('.')))) + if (i.key().startsWith(QString(*it + QLatin1Char('.')))) i = cleanedParameterMap.erase(i); else - i++; + ++i; } } } diff --git a/src/plugins/geoservices/nokia/placesv2/qplacedetailsreplyimpl.cpp b/src/plugins/geoservices/nokia/placesv2/qplacedetailsreplyimpl.cpp index 40bec231..e85b9cc7 100644 --- a/src/plugins/geoservices/nokia/placesv2/qplacedetailsreplyimpl.cpp +++ b/src/plugins/geoservices/nokia/placesv2/qplacedetailsreplyimpl.cpp @@ -269,14 +269,15 @@ void QPlaceDetailsReplyImpl::replyFinished() if (object.contains(QLatin1String("extended"))) { QJsonObject extendedObject = object.value(QLatin1String("extended")).toObject(); - foreach (const QString &key, extendedObject.keys()) { - QJsonObject attributeObject = extendedObject.value(key).toObject(); + for (auto it = extendedObject.constBegin(), end = extendedObject.constEnd(); it != end; ++it) { + QJsonObject attributeObject = it.value().toObject(); QPlaceAttribute attribute; attribute.setLabel(attributeObject.value(QLatin1String("label")).toString()); attribute.setText(attributeObject.value(QLatin1String("text")).toString()); + QString key = it.key(); if (key == QLatin1String("payment")) place.setExtendedAttribute(QPlaceAttribute::Payment, attribute); else if (key == QLatin1String("openingHours")) diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp index 0713ba10..4f44e5fd 100644 --- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp @@ -194,13 +194,12 @@ void QGeoTiledMappingManagerEngineNokia::loadCopyrightsDescriptorsFromJson(const } QJsonObject jsonObj = doc.object(); - QStringList keys = jsonObj.keys(); m_copyrights.clear(); - for (int keyIndex = 0; keyIndex < keys.count(); keyIndex++) { + for (auto it = jsonObj.constBegin(), end = jsonObj.constEnd(); it != end; ++it) { QList<CopyrightDesc> copyrightDescList; - QJsonArray descs = jsonObj[ keys[ keyIndex ] ].toArray(); + QJsonArray descs = it.value().toArray(); for (int descIndex = 0; descIndex < descs.count(); descIndex++) { CopyrightDesc copyrightDesc; QJsonObject desc = descs.at(descIndex).toObject(); @@ -225,7 +224,7 @@ void QGeoTiledMappingManagerEngineNokia::loadCopyrightsDescriptorsFromJson(const } copyrightDescList << copyrightDesc; } - m_copyrights[ keys[ keyIndex ] ] = copyrightDescList; + m_copyrights[it.key()] = copyrightDescList; } } diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp index ac20c262..6dcb28da 100644 --- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp +++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp @@ -627,18 +627,18 @@ QPlaceReply *QPlaceManagerEngineNokiaV2::initializeCategories() } //request all categories in the tree from the server - //because we don't want the root node, we remove it from the list - QStringList ids = m_tempTree.keys(); - ids.removeAll(QString()); - foreach (const QString &id, ids) { + //because we don't want the root node, we skip it + for (auto it = m_tempTree.keyBegin(), end = m_tempTree.keyEnd(); it != end; ++it) { + if (*it == QString()) + continue; QUrl requestUrl(QString::fromLatin1("http://") + m_uriProvider->getCurrentHost() + - QStringLiteral("/places/v1/categories/places/") + id); + QStringLiteral("/places/v1/categories/places/") + *it); QNetworkReply *networkReply = sendRequest(requestUrl); connect(networkReply, SIGNAL(finished()), this, SLOT(categoryReplyFinished())); connect(networkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(categoryReplyError())); - m_categoryRequests.insert(id, networkReply); + m_categoryRequests.insert(*it, networkReply); } QPlaceCategoriesReplyHere *reply = new QPlaceCategoriesReplyHere(this); diff --git a/src/positioning/qgeoareamonitorsource.cpp b/src/positioning/qgeoareamonitorsource.cpp index 734568c5..71b30aa1 100644 --- a/src/positioning/qgeoareamonitorsource.cpp +++ b/src/positioning/qgeoareamonitorsource.cpp @@ -190,11 +190,11 @@ QGeoAreaMonitorSource *QGeoAreaMonitorSource::createSource(const QString &source QStringList QGeoAreaMonitorSource::availableSources() { QStringList plugins; - QHash<QString, QJsonObject> meta = QGeoPositionInfoSourcePrivate::plugins(); - foreach (const QString &name, meta.keys()) { - if (meta.value(name).value(QStringLiteral("Monitor")).isBool() - && meta.value(name).value(QStringLiteral("Monitor")).toBool()) { - plugins << name; + const QHash<QString, QJsonObject> meta = QGeoPositionInfoSourcePrivate::plugins(); + for (auto it = meta.cbegin(), end = meta.cend(); it != end; ++it) { + if (it.value().value(QStringLiteral("Monitor")).isBool() + && it.value().value(QStringLiteral("Monitor")).toBool()) { + plugins << it.key(); } } diff --git a/src/positioning/qgeopositioninfosource.cpp b/src/positioning/qgeopositioninfosource.cpp index 0cec8eaa..48cb27ad 100644 --- a/src/positioning/qgeopositioninfosource.cpp +++ b/src/positioning/qgeopositioninfosource.cpp @@ -329,11 +329,11 @@ QGeoPositionInfoSource *QGeoPositionInfoSource::createSource(const QString &sour QStringList QGeoPositionInfoSource::availableSources() { QStringList plugins; - QHash<QString, QJsonObject> meta = QGeoPositionInfoSourcePrivate::plugins(); - foreach (const QString &name, meta.keys()) { - if (meta.value(name).value(QStringLiteral("Position")).isBool() - && meta.value(name).value(QStringLiteral("Position")).toBool()) { - plugins << name; + const QHash<QString, QJsonObject> meta = QGeoPositionInfoSourcePrivate::plugins(); + for (auto it = meta.cbegin(), end = meta.cend(); it != end; ++it) { + if (it.value().value(QStringLiteral("Position")).isBool() + && it.value().value(QStringLiteral("Position")).toBool()) { + plugins << it.key(); } } diff --git a/src/positioning/qgeosatelliteinfosource.cpp b/src/positioning/qgeosatelliteinfosource.cpp index da6eb8a0..e8a32d59 100644 --- a/src/positioning/qgeosatelliteinfosource.cpp +++ b/src/positioning/qgeosatelliteinfosource.cpp @@ -219,11 +219,11 @@ QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &so QStringList QGeoSatelliteInfoSource::availableSources() { QStringList plugins; - QHash<QString, QJsonObject> meta = QGeoPositionInfoSourcePrivate::plugins(); - foreach (const QString &name, meta.keys()) { - if (meta.value(name).value(QStringLiteral("Satellite")).isBool() - && meta.value(name).value(QStringLiteral("Satellite")).toBool()) { - plugins << name; + const QHash<QString, QJsonObject> meta = QGeoPositionInfoSourcePrivate::plugins(); + for (auto it = meta.cbegin(), end = meta.cend(); it != end; ++it) { + if (it.value().value(QStringLiteral("Satellite")).isBool() + && it.value().value(QStringLiteral("Satellite")).toBool()) { + plugins << it.key(); } } |