diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-08-14 08:46:30 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-04-05 17:02:30 +0000 |
commit | f1530d0be1ec9b2fc076188b488c6347298c4c28 (patch) | |
tree | d81b5723c445f2885293997ef95f0eecf0a933b0 | |
parent | f02b849e9721f030af7147d1fed28ce7564b95a2 (diff) |
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) <ogoffart@woboq.com>
-rw-r--r-- | src/corelib/tools/qstring.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
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<QStringRef> 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) |