diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-08-13 21:26:59 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-04-02 19:30:29 +0000 |
commit | c4ed23b3e05eeb4554571b725b24eedc99845b5f (patch) | |
tree | 27acf07c876e777cdd05410788bbd7a326a750b8 /src/corelib/tools/qstring.cpp | |
parent | 4bd81e0b822648c4663eeb58d0d08cb99bb80246 (diff) |
Optimize QString::section(QReg*Exp*)
Instead of creating lots of temporary QString objects, use QStringRefs.
Together with the two other (micro) optimizations before, this speeds
up section() by up to 2x (section_regex(IPv6)).
No test has become slower.
Change-Id: I514667004f82ddc1518fe3ee699ec5fbf96bb82f
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 14ed315710..09a3c9aa98 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -4049,9 +4049,9 @@ QString QString::section(const QString &sep, int start, int end, SectionFlags fl class qt_section_chunk { public: qt_section_chunk() {} - qt_section_chunk(int l, QString s) : length(l), string(qMove(s)) {} + qt_section_chunk(int l, QStringRef s) : length(l), string(qMove(s)) {} int length; - QString string; + QStringRef string; }; Q_DECLARE_TYPEINFO(qt_section_chunk, Q_MOVABLE_TYPE); @@ -4144,12 +4144,12 @@ QString QString::section(const QRegExp ®, int start, int end, SectionFlags fl QVector<qt_section_chunk> sections; int n = length(), m = 0, last_m = 0, last_len = 0; while ((m = sep.indexIn(*this, m)) != -1) { - sections.append(qt_section_chunk(last_len, QString(uc + last_m, m - last_m))); + sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, m - last_m))); last_m = m; last_len = sep.matchedLength(); m += qMax(sep.matchedLength(), 1); } - sections.append(qt_section_chunk(last_len, QString(uc + last_m, n - last_m))); + sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, n - last_m))); return extractSections(sections, start, end, flags); } @@ -4192,11 +4192,11 @@ QString QString::section(const QRegularExpression &re, int start, int end, Secti while (iterator.hasNext()) { QRegularExpressionMatch match = iterator.next(); m = match.capturedStart(); - sections.append(qt_section_chunk(last_len, QString(uc + last_m, m - last_m))); + sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, m - last_m))); last_m = m; last_len = match.capturedLength(); } - sections.append(qt_section_chunk(last_len, QString(uc + last_m, n - last_m))); + sections.append(qt_section_chunk(last_len, QStringRef(this, last_m, n - last_m))); return extractSections(sections, start, end, flags); } |