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>
This commit is contained in:
parent
f02b849e97
commit
f1530d0be1
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user