Optimize string building in QImage::text()
- Don't iterate over QMap::keys(), but directly over the map, saving a temporary QList and double lookups. - Always append the item separator, and chop it off once at the end, which allows to fold the separator into the existing string builder expression. Change-Id: Ibd20ea292695098e0fc575025b1827a75aabfd1e Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>bb10
parent
4bc923b628
commit
257cc69bed
|
|
@ -3752,11 +3752,10 @@ QString QImage::text(const QString &key) const
|
|||
return d->text.value(key);
|
||||
|
||||
QString tmp;
|
||||
foreach (const QString &key, d->text.keys()) {
|
||||
if (!tmp.isEmpty())
|
||||
tmp += QLatin1String("\n\n");
|
||||
tmp += key + QLatin1String(": ") + d->text.value(key).simplified();
|
||||
}
|
||||
for (auto it = d->text.begin(), end = d->text.end(); it != end; ++it)
|
||||
tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n");
|
||||
if (!tmp.isEmpty())
|
||||
tmp.chop(2); // remove final \n\n
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue