qdoc: don't hold QQmlJS::AST::SourceLocation in QLists

QQmlJS::AST::SourceLocation wasn't marked as movable, and it is larger
than void*, so QList<SourceLocation> is horribly inefficient.

Fix by marking as movable primitive and holding in QVector instead.

The same fix probably is required in QtDeclarative, too.

Change-Id: I4e0d2cd32b7e03205d59cbc9900287f77045154a
Reviewed-by: Martin Smith <martin.smith@digia.com>
bb10
Marc Mutz 2015-06-20 12:58:10 +02:00
parent 08e0963e08
commit 2422251ee5
9 changed files with 39 additions and 36 deletions

View File

@ -68,7 +68,7 @@ bool JsCodeMarker::recognizeCode(const QString &code)
QQmlJS::Parser parser(&engine);
QString newCode = code;
QList<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
QVector<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
lexer.setCode(newCode, 1);
return parser.parseProgram();
@ -115,7 +115,7 @@ QString JsCodeMarker::addMarkUp(const QString &code,
QQmlJS::Lexer lexer(&engine);
QString newCode = code;
QList<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
QVector<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
lexer.setCode(newCode, 1);
QQmlJS::Parser parser(&engine);

View File

@ -166,7 +166,7 @@ QString QmlCodeMarker::addMarkUp(const QString &code,
QQmlJS::Lexer lexer(&engine);
QString newCode = code;
QList<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
QVector<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
lexer.setCode(newCode, 1);
QQmlJS::Parser parser(&engine);
@ -209,11 +209,11 @@ static void replaceWithSpace(QString &str, int idx, int n)
Searches for ".pragma <value>" or ".import <stuff>" declarations
in \a script. Currently supported pragmas are: library
*/
QList<QQmlJS::AST::SourceLocation> QmlCodeMarker::extractPragmas(QString &script)
QVector<QQmlJS::AST::SourceLocation> QmlCodeMarker::extractPragmas(QString &script)
{
const QString pragma(QLatin1String("pragma"));
const QString library(QLatin1String("library"));
QList<QQmlJS::AST::SourceLocation> removed;
QVector<QQmlJS::AST::SourceLocation> removed;
QQmlJS::Lexer l(0);
l.setCode(script, 0);

View File

@ -66,7 +66,7 @@ public:
virtual QString functionEndRegExp(const QString &funcName) Q_DECL_OVERRIDE;
/* Copied from src/declarative/qml/qdeclarativescriptparser.cpp */
QList<QQmlJS::AST::SourceLocation> extractPragmas(QString &script);
QVector<QQmlJS::AST::SourceLocation> extractPragmas(QString &script);
private:
QString addMarkUp(const QString &code, const Node *relative,

View File

@ -42,7 +42,7 @@
QT_BEGIN_NAMESPACE
QmlMarkupVisitor::QmlMarkupVisitor(const QString &source,
const QList<QQmlJS::AST::SourceLocation> &pragmas,
const QVector<QQmlJS::AST::SourceLocation> &pragmas,
QQmlJS::Engine *engine)
{
this->source = source;
@ -54,7 +54,7 @@ QmlMarkupVisitor::QmlMarkupVisitor(const QString &source,
// Merge the lists of locations of pragmas and comments in the source code.
int i = 0;
int j = 0;
const QList<QQmlJS::AST::SourceLocation> comments = engine->comments();
const QVector<QQmlJS::AST::SourceLocation> comments = engine->comments();
while (i < comments.size() && j < pragmas.length()) {
if (comments[i].offset < pragmas[j].offset) {
extraTypes.append(Comment);

View File

@ -50,7 +50,7 @@ public:
};
QmlMarkupVisitor(const QString &code,
const QList<QQmlJS::AST::SourceLocation> &pragmas,
const QVector<QQmlJS::AST::SourceLocation> &pragmas,
QQmlJS::Engine *engine);
virtual ~QmlMarkupVisitor();
@ -158,7 +158,7 @@ private:
QQmlJS::Engine *engine;
QList<ExtraType> extraTypes;
QList<QQmlJS::AST::SourceLocation> extraLocations;
QVector<QQmlJS::AST::SourceLocation> extraLocations;
QString source;
QString output;
quint32 cursor;

View File

@ -37,6 +37,7 @@
#include "qqmljsglobal_p.h"
#include <QtCore/qglobal.h>
#include <QtCore/qtypeinfo.h>
//
// W A R N I N G
@ -53,27 +54,6 @@ QT_QML_BEGIN_NAMESPACE
namespace QQmlJS { namespace AST {
class SourceLocation
{
public:
explicit SourceLocation(quint32 offset = 0, quint32 length = 0, quint32 line = 0, quint32 column = 0)
: offset(offset), length(length),
startLine(line), startColumn(column)
{ }
bool isValid() const { return length != 0; }
quint32 begin() const { return offset; }
quint32 end() const { return offset + length; }
// attributes
// ### encode
quint32 offset;
quint32 length;
quint32 startLine;
quint32 startColumn;
};
class Visitor;
class Node;
class ExpressionNode;
@ -176,8 +156,31 @@ class UiQualifiedId;
class UiQualifiedPragmaId;
class UiHeaderItemList;
class SourceLocation
{
public:
explicit SourceLocation(quint32 offset = 0, quint32 length = 0, quint32 line = 0, quint32 column = 0)
: offset(offset), length(length),
startLine(line), startColumn(column)
{ }
bool isValid() const { return length != 0; }
quint32 begin() const { return offset; }
quint32 end() const { return offset + length; }
// attributes
// ### encode
quint32 offset;
quint32 length;
quint32 startLine;
quint32 startColumn;
};
} } // namespace AST
Q_DECLARE_TYPEINFO(QQmlJS::AST::SourceLocation, Q_PRIMITIVE_TYPE);
QT_QML_END_NAMESPACE
#endif

View File

@ -125,7 +125,7 @@ void Engine::setCode(const QString &code)
void Engine::addComment(int pos, int len, int line, int col)
{ if (len > 0) _comments.append(QQmlJS::AST::SourceLocation(pos, len, line, col)); }
QList<QQmlJS::AST::SourceLocation> Engine::comments() const
QVector<QQmlJS::AST::SourceLocation> Engine::comments() const
{ return _comments; }
Lexer *Engine::lexer() const

View File

@ -50,7 +50,7 @@
#include "qqmljsmemorypool_p.h"
#include <QtCore/qstring.h>
#include <QtCore/qset.h>
#include <QtCore/qvector.h>
QT_QML_BEGIN_NAMESPACE
@ -87,7 +87,7 @@ class QML_PARSER_EXPORT Engine
Lexer *_lexer;
Directives *_directives;
MemoryPool _pool;
QList<AST::SourceLocation> _comments;
QVector<AST::SourceLocation> _comments;
QString _extraCode;
QString _code;
@ -99,7 +99,7 @@ public:
const QString &code() const { return _code; }
void addComment(int pos, int len, int line, int col);
QList<AST::SourceLocation> comments() const;
QVector<AST::SourceLocation> comments() const;
Lexer *lexer() const;
void setLexer(Lexer *lexer);

View File

@ -119,7 +119,7 @@ QmlDocVisitor::~QmlDocVisitor()
*/
QQmlJS::AST::SourceLocation QmlDocVisitor::precedingComment(quint32 offset) const
{
QListIterator<QQmlJS::AST::SourceLocation> it(engine->comments());
QVectorIterator<QQmlJS::AST::SourceLocation> it(engine->comments());
it.toBack();
while (it.hasPrevious()) {