From cb60c5c66ae9460352e51d063af6261d4cc76d38 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 20 Jun 2015 12:42:46 +0200 Subject: qdoc: fix one of the most expensive loops in Qt QQmlJS::Engine::comments() returns a QList 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) --- src/tools/qdoc/qmlmarkupvisitor.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') 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 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; } -- cgit v1.2.3