From 9f7b20829ac9e13e98100549ec677efcf67effce Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Mon, 13 Dec 2010 13:36:08 +0000 Subject: [PATCH] Replace slow foreach constructs with faster ones Acked by Marco svn path=/trunk/KDE/kdelibs/; revision=1206126 --- datacontainer.cpp | 11 +++++++---- private/serviceprovider.cpp | 10 +++++++--- theme.cpp | 6 ++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/datacontainer.cpp b/datacontainer.cpp index ede4843de..ef01fd613 100644 --- a/datacontainer.cpp +++ b/datacontainer.cpp @@ -262,16 +262,19 @@ void DataContainerPrivate::populateFromStoredData(KJob *job) DataEngine::Data dataToInsert; ServiceJob* ret = dynamic_cast(job); - QHash h = ret->result().toHash(); - foreach (QString key, h.keys()) { + const QHash h = ret->result().toHash(); + QHash::const_iterator it = h.begin(); + QHash::const_iterator itEnd = h.end(); + for ( ; it != itEnd; ++it) { + QString key = it.key(); if (key.startsWith("base64-")) { - QByteArray b = QByteArray::fromBase64(h[key].toString().toAscii()); + QByteArray b = QByteArray::fromBase64(it.value().toString().toAscii()); QDataStream ds(&b, QIODevice::ReadOnly); QVariant v(ds); key.remove(0, 7); dataToInsert.insert(key, v); } else { - dataToInsert.insert(key, h[key]); + dataToInsert.insert(key, it.value()); } } diff --git a/private/serviceprovider.cpp b/private/serviceprovider.cpp index 112940a85..6f1d90592 100644 --- a/private/serviceprovider.cpp +++ b/private/serviceprovider.cpp @@ -88,9 +88,13 @@ void ServiceProvider::startOperationCall(Jolie::Message message) kDebug() << "====PARAMETERS===="; //write the parameters into the operation description - foreach (const QString &key, parameters.keys()) { - kDebug() << "key = " << key << ", value = " << parameters.value(key); - description.writeEntry(key, parameters.value(key)); + QMap::const_iterator it = parameters.constBegin(); + QMap::const_iterator itEnd = parameters.constEnd(); + for ( ; it != itEnd; ++it) { + const QString key = it.key(); + const QVariant value = it.value(); + kDebug() << "key = " << key << ", value = " << value; + description.writeEntry(key, value); } m_service->setDestination(JolieMessage::field(JolieMessage::Field::DESTINATION, message)); diff --git a/theme.cpp b/theme.cpp index eaf97d3c1..48d45a985 100644 --- a/theme.cpp +++ b/theme.cpp @@ -371,8 +371,10 @@ const QString ThemePrivate::processStyleSheet(const QString &css) elements["%fontfamily"] = font.family(); elements["%smallfontsize"] = QString("%1pt").arg(KGlobalSettings::smallestReadableFont().pointSize()); - foreach (const QString &k, elements.keys()) { - stylesheet.replace(k, elements[k]); + QHash::const_iterator it = elements.constBegin(); + QHash::const_iterator itEnd = elements.constEnd(); + for ( ; it != itEnd; ++it) { + stylesheet.replace(it.key(), it.value()); } return stylesheet; }