From d58d7a5376ccee53544e5141e442350ba4ad8089 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 28 Aug 2016 19:23:45 +0200 Subject: Add QStringList::join(QLatin1String) overload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Costs only ~300B in text size in QtCore, which is roughly compensated by savings in other QtBase libraries, even without specifically porting users to QL1S. Of course, the raison d'ĂȘtre for this overload is avoiding the expensive QLatin1String -> QString conversion which, for small lists, can take up to 50% of the total runtime (assuming memory allocations dominate over scanning and copying the list). [ChangeLog][QtCore][QStringList] Added join(QLatin1String) overload. Change-Id: I91d7e1d4e2c76d6dc79f2b750cf8e256dd4e0ab6 Reviewed-by: Thiago Macieira --- src/corelib/tools/qstringlist.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib/tools/qstringlist.h') diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h index 87f15528bf..720d7d7419 100644 --- a/src/corelib/tools/qstringlist.h +++ b/src/corelib/tools/qstringlist.h @@ -73,6 +73,7 @@ public: inline int removeDuplicates(); inline QString join(const QString &sep) const; + inline QString join(QLatin1String sep) const; inline QString join(QChar sep) const; inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -159,6 +160,7 @@ namespace QtPrivate { void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs); int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, int seplen); + Q_CORE_EXPORT QString QStringList_join(const QStringList &list, QLatin1String sep); QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str, Qt::CaseSensitivity cs); @@ -200,6 +202,11 @@ inline QString QListSpecialMethods::join(const QString &sep) const return QtPrivate::QStringList_join(self(), sep.constData(), sep.length()); } +QString QListSpecialMethods::join(QLatin1String sep) const +{ + return QtPrivate::QStringList_join(*self(), sep); +} + inline QString QListSpecialMethods::join(QChar sep) const { return QtPrivate::QStringList_join(self(), &sep, 1); -- cgit v1.2.3