summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-01-26 16:32:25 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2010-02-01 11:01:37 (GMT)
commitbed5a692d9306be95c3fe843fcc6057bbe3ae8e2 (patch)
tree1708edb21a2be05daa6f0f63400464ec38dc3675
parent5ce59a5796cb4a252ca30e099fc8ff592d558d76 (diff)
downloadQt-bed5a692d9306be95c3fe843fcc6057bbe3ae8e2.zip
Qt-bed5a692d9306be95c3fe843fcc6057bbe3ae8e2.tar.gz
Qt-bed5a692d9306be95c3fe843fcc6057bbe3ae8e2.tar.bz2
Optimise QStringList::join by pre-allocating the final size.
This avoids a number of reallocations due to appending. This patch was contributed to us. Task-number: QTBUG-3242 Reviewed-by: Thiago Macieira (cherry picked from commit 7461ed5227e3002c4a6f74d458aa0255b7c1217d)
-rw-r--r--src/corelib/tools/qstringlist.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp
index 4b0f488..e9bdf57 100644
--- a/src/corelib/tools/qstringlist.cpp
+++ b/src/corelib/tools/qstringlist.cpp
@@ -404,7 +404,17 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &r
*/
QString QtPrivate::QStringList_join(const QStringList *that, const QString &sep)
{
+ int totalLength = 0;
+ const int size = that->size();
+
+ for (int i = 0; i < size; ++i)
+ totalLength += that->at(i).size();
+
+ if(size > 0)
+ totalLength += sep.size() * (size - 1);
+
QString res;
+ res.reserve(totalLength);
for (int i = 0; i < that->size(); ++i) {
if (i)
res += sep;