Replace slow foreach constructs with faster ones

Acked by Marco

svn path=/trunk/KDE/kdelibs/; revision=1206126
This commit is contained in:
Albert Astals Cid 2010-12-13 13:36:08 +00:00
parent 1a3133cb31
commit 9f7b20829a
3 changed files with 18 additions and 9 deletions

View File

@ -262,16 +262,19 @@ void DataContainerPrivate::populateFromStoredData(KJob *job)
DataEngine::Data dataToInsert;
ServiceJob* ret = dynamic_cast<ServiceJob*>(job);
QHash<QString, QVariant> h = ret->result().toHash();
foreach (QString key, h.keys()) {
const QHash<QString, QVariant> h = ret->result().toHash();
QHash<QString, QVariant>::const_iterator it = h.begin();
QHash<QString, QVariant>::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());
}
}

View File

@ -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<QString, QVariant>::const_iterator it = parameters.constBegin();
QMap<QString, QVariant>::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));

View File

@ -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<QString, QString>::const_iterator it = elements.constBegin();
QHash<QString, QString>::const_iterator itEnd = elements.constEnd();
for ( ; it != itEnd; ++it) {
stylesheet.replace(it.key(), it.value());
}
return stylesheet;
}