From f1530d0be1ec9b2fc076188b488c6347298c4c28 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 14 Aug 2014 08:46:30 +0200 Subject: Optimize QString::section(QString) The port from split() to splitRef() speeds up typical section() calls (where the separator is included) by ca. 1/3. The complete truth includes that section() calls where the separator is not found seem to have gotten twice slower. But that's a corner-case. Change-Id: I7e957cb65fccfd095ac522d523aef3464425e4e4 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qstring.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 09a3c9aa98..01fe98f239 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -3997,10 +3997,9 @@ int QString::count(const QRegularExpression &re) const QString QString::section(const QString &sep, int start, int end, SectionFlags flags) const { - QStringList sections = split(sep, KeepEmptyParts, - (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive); + const QVector sections = splitRef(sep, KeepEmptyParts, + (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive); const int sectionsSize = sections.size(); - if (!(flags & SectionSkipEmpty)) { if (start < 0) start += sectionsSize; @@ -4024,7 +4023,7 @@ QString QString::section(const QString &sep, int start, int end, SectionFlags fl QString ret; int first_i = start, last_i = end; for (int i = 0; x <= end && i < sectionsSize; ++i) { - QString section = sections.at(i); + const QStringRef §ion = sections.at(i); const bool empty = section.isEmpty(); if (x >= start) { if(x == start) -- cgit v1.2.3