summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-16 14:37:44 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-16 18:10:39 (GMT)
commit5af4e7d0e44be7d35c38c439fa9fc42f54ccd09b (patch)
treeffcf5e23c679ac4a753445403a4aa596ac188b35 /src/corelib
parent82027baa2c7705ae49300ce3ca0ac9eb4add2e96 (diff)
downloadQt-5af4e7d0e44be7d35c38c439fa9fc42f54ccd09b.zip
Qt-5af4e7d0e44be7d35c38c439fa9fc42f54ccd09b.tar.gz
Qt-5af4e7d0e44be7d35c38c439fa9fc42f54ccd09b.tar.bz2
avoid double reallocation in string-growing replace() case
detach() followed by resize() is suboptimal, as it first creates an identically sized copy, and then a differently sized one. Reviewed-by: joao Reviewed-by: denis
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qstring.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index f85d794..cce313b 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -1800,13 +1800,14 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar
}
QT_TRY {
- detach();
if (blen == alen) {
// replace in place
+ detach();
for (int i = 0; i < nIndices; ++i)
memcpy(d->data + indices[i], afterBuffer, alen * sizeof(QChar));
} else if (alen < blen) {
// replace from front
+ detach();
uint to = indices[0];
if (alen)
memcpy(d->data+to, after, alen*sizeof(QChar));