diff options
author | Robin Burchell <robin.burchell@viroteck.net> | 2016-07-09 12:53:53 +0200 |
---|---|---|
committer | Robin Burchell <robin.burchell@viroteck.net> | 2016-07-11 12:30:31 +0000 |
commit | ca9ed9619f1c21ba0b3ef7687bbbad9eaf2bd39a (patch) | |
tree | 3047e88f2bcd443117cb9f33f72f701496d437d1 /src | |
parent | d737a8ed54dea6d7e2b030cf5f955f2ea010d94b (diff) |
Improve performance of Qt::mightBeRichText by using QStringRef
I noted this taking around 1% of QtQuick Text creation with a few simple bindings
which is quite considerable, so hopefully improvements here will add up gradually.
Also add a benchmark measuring changes:
Test | From | To | Details
+--------------------------------------+----------------+----------------+-----------------------+
mightBeRichText:br-invalidspace | 14466.00 instr | 10563.00 instr | -26.98% FASTER! :)
mightBeRichText:br-nospace | 18581.00 instr | 14635.00 instr | -21.24% FASTER! :)
mightBeRichText:br-space | 18470.00 instr | 14377.00 instr | -22.16% FASTER! :)
mightBeRichText:documentation-header | 16336.00 instr | 12992.00 instr | -20.47% FASTER! :)
mightBeRichText:empty | 2618.00 instr | 2618.00 instr | more or less the same
mightBeRichText:invalid closing tag | 11102.00 instr | 7159.00 instr | -35.52% FASTER! :)
mightBeRichText:no tags | 12503.00 instr | 8581.00 instr | -31.37% FASTER! :)
mightBeRichText:simple | 17316.00 instr | 14074.00 instr | -18.72% FASTER! :)
mightBeRichText:simple2 | 14394.00 instr | 10745.00 instr | -25.35% FASTER! :)
+--------------------------------------+----------------+----------------+-----------------------+
Overall result | -201.81% :)
Change-Id: I1817a69959d176b381bcbf27b72bb751885c3e9b
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index a3dbf455cf..75899dec80 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -94,7 +94,7 @@ bool Qt::mightBeRichText(const QString& text) ++start; // skip a leading <?xml ... ?> as for example with xhtml - if (text.mid(start, 5) == QLatin1String("<?xml")) { + if (text.midRef(start, 5).compare(QLatin1String("<?xml")) == 0) { while (start < text.length()) { if (text.at(start) == QLatin1Char('?') && start + 2 < text.length() @@ -109,12 +109,12 @@ bool Qt::mightBeRichText(const QString& text) ++start; } - if (text.mid(start, 5).toLower() == QLatin1String("<!doc")) + if (text.midRef(start, 5).compare(QLatin1String("<!doc"), Qt::CaseInsensitive) == 0) return true; int open = start; while (open < text.length() && text.at(open) != QLatin1Char('<') && text.at(open) != QLatin1Char('\n')) { - if (text.at(open) == QLatin1Char('&') && text.mid(open+1,3) == QLatin1String("lt;")) + if (text.at(open) == QLatin1Char('&') && text.midRef(open + 1, 3) == QLatin1String("lt;")) return true; // support desperate attempt of user to see <...> ++open; } |