summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-06-20 12:42:46 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-06-21 11:43:52 +0000
commitcb60c5c66ae9460352e51d063af6261d4cc76d38 (patch)
treeb169c61f685b1f7fee5298d10bead2602ef70642
parent55655abfaf1fbe09af2eedfde413e862bc6c85e2 (diff)
qdoc: fix one of the most expensive loops in Qt
QQmlJS::Engine::comments() returns a QList<QQmlJ::AST::SourceLocation> by value. The QList is horribly inefficient, but that will be topic of a separate patch. The loop in QmlMarkupVisitor did not store the result of comments() in a local variable, it called engine->comments() whenever it referenced it, which was _three_ times per loop iteration. Two of those references applied op[] to the rvalue engine->comments(), which, being mutable, detaches. _Twice_ per loop, with a QList that heap-allocates its elements!. And that was followed by a similar loop. Fix by using a local const copy of the list to iterate over. The loop termination condition also looks fishy (j is used to index into the comments, but is not checked against comments.size()), but apparently qdoc works fine with it so far, so don't try to fix. The copy of QQmlJS in QtDeclarative is not affected by this (qdoc-specific code). Change-Id: I133c35dc9293609dfb8ad633e2d82399223b508b Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--src/tools/qdoc/qmlmarkupvisitor.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/tools/qdoc/qmlmarkupvisitor.cpp b/src/tools/qdoc/qmlmarkupvisitor.cpp
index ee86b6de32..735dea548d 100644
--- a/src/tools/qdoc/qmlmarkupvisitor.cpp
+++ b/src/tools/qdoc/qmlmarkupvisitor.cpp
@@ -54,21 +54,22 @@ QmlMarkupVisitor::QmlMarkupVisitor(const QString &source,
// Merge the lists of locations of pragmas and comments in the source code.
int i = 0;
int j = 0;
- while (i < engine->comments().length() && j < pragmas.length()) {
- if (engine->comments()[i].offset < pragmas[j].offset) {
+ const QList<QQmlJS::AST::SourceLocation> comments = engine->comments();
+ while (i < comments.size() && j < pragmas.length()) {
+ if (comments[i].offset < pragmas[j].offset) {
extraTypes.append(Comment);
- extraLocations.append(engine->comments()[i]);
+ extraLocations.append(comments[i]);
++i;
} else {
extraTypes.append(Pragma);
- extraLocations.append(engine->comments()[j]);
+ extraLocations.append(comments[j]);
++j;
}
}
- while (i < engine->comments().length()) {
+ while (i < comments.size()) {
extraTypes.append(Comment);
- extraLocations.append(engine->comments()[i]);
+ extraLocations.append(comments[i]);
++i;
}