diff options
author | Simon Hausmann <[email protected]> | 2013-10-23 16:24:58 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-10-29 21:56:07 +0100 |
commit | ba6fc15d729304c136447242de2410fbf4f020cd (patch) | |
tree | 3ad8a9575de295c9102eae125f64246bec854852 /src/qml/compiler/qqmlcodegenerator.cpp | |
parent | c32265bfc562db23b7c894306ec61fd22111a7b1 (diff) |
Speed up id object lookups
We can resolve lookups for objects referenced by id at QML compile time
and use a run-time helper to extract the id object out of the QML context
data by index instead of name.
Dependencies to id objects are also tracked at compile time and registered
separately before entering the generated function code.
The lookup of id objects is encoded in the IR as special member lookups.
Members will also then in the future be used to for property lookups in context
and scope properties, as well as any other property lookups in QObjects where
we can determine the meta-object.
Change-Id: I36cf3ceb11b51a983da6cad5b61c3bf574acc20a
Reviewed-by: Lars Knoll <[email protected]>
Diffstat (limited to 'src/qml/compiler/qqmlcodegenerator.cpp')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index 2aa5aa5a3c..cbf58599ac 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -1201,18 +1201,23 @@ int QmlUnitGenerator::getStringId(const QString &str) const QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QString &fileName, ParsedQML *output) { return generateJSCodeForFunctionsAndBindings(fileName, output->code, &output->jsModule, &output->jsParserEngine, - output->program, output->functions); + output->program, /* ### */output->program, output->functions); } QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QString &fileName, const QString &sourceCode, V4IR::Module *jsModule, - QQmlJS::Engine *jsEngine, AST::UiProgram *qmlRoot, const QList<AST::Node*> &functions) + QQmlJS::Engine *jsEngine, AST::UiProgram *qmlRoot, AST::Node *contextRoot, + const QList<AST::Node*> &functions, + const ObjectIdMapping &objectIds) { + this->idObjects = objectIds; + QVector<int> runtimeFunctionIndices(functions.size()); _module = jsModule; _module->setFileName(fileName); - QmlScanner scan(this, sourceCode); - scan.begin(qmlRoot, QmlBinding); + ScanFunctions scan(this, sourceCode, GlobalCode); + scan.enterEnvironment(0, QmlBinding); + scan.enterQmlScope(qmlRoot, "context scope"); foreach (AST::Node *node, functions) { Q_ASSERT(node != qmlRoot); AST::FunctionDeclaration *function = AST::cast<AST::FunctionDeclaration*>(node); @@ -1221,7 +1226,8 @@ QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QString &fil scan(function ? function->body : node); scan.leaveEnvironment(); } - scan.end(); + scan.leaveEnvironment(); + scan.leaveEnvironment(); _env = 0; _function = _module->functions.at(defineFunction(QString("context scope"), qmlRoot, 0, 0)); @@ -1267,16 +1273,25 @@ QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QString &fil return runtimeFunctionIndices; } - -void JSCodeGen::QmlScanner::begin(AST::Node *rootNode, CompilationMode compilationMode) +V4IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int col) const { - enterEnvironment(0, compilationMode); - enterFunction(rootNode, "context scope", 0, 0, 0, /*isExpression*/false); -} + V4IR::Expr *result = 0; + // Implement QML lookup semantics in the current file context. -void JSCodeGen::QmlScanner::end() -{ - leaveEnvironment(); + // Look for IDs first. + foreach (const IdMapping &mapping, idObjects) + if (name == mapping.name) { + result = _block->QML_CONTEXT_ID_MEMBER(mapping.name, mapping.idIndex, line, col); + break; + } + + if (result) { + _function->hasQmlDependencies = true; + return result; + } + + // fall back to name lookup at run-time. + return 0; } SignalHandlerConverter::SignalHandlerConverter(QQmlEnginePrivate *enginePrivate, ParsedQML *parsedQML, |