From 276d6cf239bdb0a39ae589e13f60b2a31a2efb60 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 9 Feb 2016 12:14:40 +0100 Subject: [PATCH] QImage: split strings with splitRef() in convertWithPalette() Optimize the string splitting by using splitRef(), avoiding the creation of lots of substrings. Twice. While touching the for loop, port to C++11 range-for. Change-Id: Ia666896bc5b96c4b6973498cc4a9eeb24cadba6d Reviewed-by: Lars Knoll --- src/gui/image/qimage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 09c92b45a4..24838080e7 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -2070,10 +2070,10 @@ static QImage convertWithPalette(const QImage &src, QImage::Format format, dest.setColorTable(clut); QString textsKeys = src.text(); - QStringList textKeyList = textsKeys.split(QLatin1Char('\n'), QString::SkipEmptyParts); - foreach (const QString &textKey, textKeyList) { - QStringList textKeySplitted = textKey.split(QLatin1String(": ")); - dest.setText(textKeySplitted[0], textKeySplitted[1]); + const auto textKeyList = textsKeys.splitRef(QLatin1Char('\n'), QString::SkipEmptyParts); + for (const auto &textKey : textKeyList) { + const auto textKeySplitted = textKey.split(QLatin1String(": ")); + dest.setText(textKeySplitted[0].toString(), textKeySplitted[1].toString()); } int h = src.height();