summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-09 12:28:04 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-02-11 19:26:11 +0000
commit257cc69bedebf924bcabf0ff24e237b8705260ad (patch)
treecb1a28933718551c496f289ef00c5b64e7c0b122 /src/gui
parent4bc923b6281dcbdc610133f1c47523999ef8c153 (diff)
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>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qimage.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 24838080e7..37b7b18522 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -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;
}