diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-05-18 18:38:25 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-09-03 13:41:55 +0200 |
commit | 68e04c3ac148bcbe71f2deeb7288563f6cdbcab5 (patch) | |
tree | 79970daa0b1b7e6393653a5363a6883f4896e66c /src/corelib/tools/qstringlist.cpp | |
parent | 64a8c78538275b8dbb9d2cbbb1f7b06b247fbe6b (diff) |
QStringList::join: add an overload taking a single QChar
This overload avoids the needless heap allocation that the traditional
overload incurs due to the implicit QChar -> QString conversion
involved there.
In order to share the implementation between the two overloads,
QStringList_join now takes the separator as a (Char*,int) tuple
instead of as a QString.
Change-Id: I92961f13a3f19099de2a6e2df9f4789a12fc83a0
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qstringlist.cpp')
-rw-r--r-- | src/corelib/tools/qstringlist.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index 0f06ad651f..2e32d6d9e9 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -434,7 +434,13 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegularEx \sa QString::split() */ -QString QtPrivate::QStringList_join(const QStringList *that, const QString &sep) + +/*! + \fn QString QStringList::join(QChar separator) const + \since 5.0 + \overload join() +*/ +QString QtPrivate::QStringList_join(const QStringList *that, const QChar *sep, int seplen) { int totalLength = 0; const int size = that->size(); @@ -443,7 +449,7 @@ QString QtPrivate::QStringList_join(const QStringList *that, const QString &sep) totalLength += that->at(i).size(); if(size > 0) - totalLength += sep.size() * (size - 1); + totalLength += seplen * (size - 1); QString res; if (totalLength == 0) @@ -451,7 +457,7 @@ QString QtPrivate::QStringList_join(const QStringList *that, const QString &sep) res.reserve(totalLength); for (int i = 0; i < that->size(); ++i) { if (i) - res += sep; + res.append(sep, seplen); res += that->at(i); } return res; |