aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-02-22 18:13:29 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-29 05:21:36 +0100
commit7fa6fcd30cb4a688eae744cae4abf9f263c16616 (patch)
tree860605cea43423860c040bc587fe9016e9033e8e /src
parentab727e6702e949c8f36649f16a81780746ebb2de (diff)
Avoid unneccessary duplication of string data.
Check for the existence of new line characters before trying to replace them. There's some redundancy if the characters are found but for single line strings we avoid the detach in replace. Change-Id: I48ccc614601a6f356b3d2e68f617e112c100bbdd Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquicktext.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index 28491d8f75..fd8ffe501b 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -305,9 +305,17 @@ void QQuickTextPrivate::updateLayout()
formatModifiesFontSize = fontSizeModified;
} else {
layout.clearAdditionalFormats();
- multilengthEos = text.indexOf(QLatin1Char('\x9c'));
- QString tmp = multilengthEos != -1 ? text.mid(0, multilengthEos) : text;
- tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
+ QString tmp = text;
+ multilengthEos = tmp.indexOf(QLatin1Char('\x9c'));
+ if (multilengthEos != -1) {
+ tmp = tmp.mid(0, multilengthEos);
+ tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
+ } else if (tmp.contains(QLatin1Char('\n'))) {
+ // Replace always does a detach. Checking for the new line character first
+ // means iterating over those items again if found but prevents a realloc
+ // otherwise.
+ tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
+ }
layout.setText(tmp);
}
textHasChanged = false;