aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-10-29 13:02:48 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-25 22:04:42 +0100
commit71e498adc4d8af11205de2eeefc50ab9eb1ad497 (patch)
treea5caa4d98520102fe9c8b70e76c62315341291a4 /src
parentcf5185d1872f75b82876dd4e4ecdc3d27240f942 (diff)
Speed up repeated context, scope and import script lookups
Instead of querying for the context, scope or imported scripts object on each access, do it once at the beginning of the expression in the IR and re-use the temp. The optimizer will optimize away unused temps. Change-Id: I703e737469030c4454d23c567873012a2b537d71 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qqmlcodegenerator.cpp37
-rw-r--r--src/qml/compiler/qqmlcodegenerator_p.h5
-rw-r--r--src/qml/compiler/qv4codegen.cpp2
-rw-r--r--src/qml/compiler/qv4codegen_p.h1
4 files changed, 36 insertions, 9 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp
index 7d6a5ad1bc..02f21569e4 100644
--- a/src/qml/compiler/qqmlcodegenerator.cpp
+++ b/src/qml/compiler/qqmlcodegenerator.cpp
@@ -1208,6 +1208,11 @@ JSCodeGen::JSCodeGen(QQmlEnginePrivate *enginePrivate, const QString &fileName,
, jsEngine(jsEngine)
, qmlRoot(qmlRoot)
, imports(imports)
+ , _contextObject(0)
+ , _scopeObject(0)
+ , _contextObjectTemp(-1)
+ , _scopeObjectTemp(-1)
+ , _importedScriptsTemp(-1)
{
_module = jsModule;
_module->setFileName(fileName);
@@ -1362,8 +1367,27 @@ static void initMetaObjectResolver(V4IR::MemberExpressionResolver *resolver, QQm
resolver->data = metaObject;
}
+void JSCodeGen::beginFunctionBodyHook()
+{
+ _contextObjectTemp = _block->newTemp();
+ _scopeObjectTemp = _block->newTemp();
+ _importedScriptsTemp = _block->newTemp();
+
+ V4IR::Temp *temp = _block->TEMP(_contextObjectTemp);
+ initMetaObjectResolver(&temp->memberResolver, _contextObject);
+ move(temp, _block->NAME(V4IR::Name::builtin_qml_context_object, 0, 0));
+
+ temp = _block->TEMP(_scopeObjectTemp);
+ initMetaObjectResolver(&temp->memberResolver, _scopeObject);
+ move(temp, _block->NAME(V4IR::Name::builtin_qml_scope_object, 0, 0));
+
+ move(_block->TEMP(_importedScriptsTemp), _block->NAME(V4IR::Name::builtin_qml_imported_scripts_object, 0, 0));
+}
+
V4IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int col)
{
+ Q_UNUSED(line)
+ Q_UNUSED(col)
// Implement QML lookup semantics in the current file context.
//
// Note: We do not check if properties of the qml scope object or context object
@@ -1387,7 +1411,7 @@ V4IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int col
QQmlTypeNameCache::Result r = imports->query(name);
if (r.isValid()) {
if (r.scriptIndex != -1)
- return subscript(_block->NAME(V4IR::Name::builtin_qml_imported_scripts_object, line, col), _block->CONST(V4IR::NumberType, r.scriptIndex));
+ return subscript(_block->TEMP(_importedScriptsTemp), _block->CONST(V4IR::NumberType, r.scriptIndex));
else
return 0; // TODO: We can't do fast lookup for these yet.
}
@@ -1401,12 +1425,9 @@ V4IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int col
if (pd) {
if (!pd->isConstant())
_function->scopeObjectDependencies.insert(pd);
- int temp = _block->newTemp();
- _block->MOVE(_block->TEMP(temp), _block->NAME(V4IR::Name::builtin_qml_scope_object, line, col));
- V4IR::Temp *base = _block->TEMP(temp);
+ V4IR::Temp *base = _block->TEMP(_scopeObjectTemp);
initMetaObjectResolver(&base->memberResolver, _scopeObject);
- return _block->QML_QOBJECT_PROPERTY(base,
- _function->newString(name), pd);
+ return _block->QML_QOBJECT_PROPERTY(base, _function->newString(name), pd);
}
}
@@ -1418,9 +1439,7 @@ V4IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int col
if (pd) {
if (!pd->isConstant())
_function->contextObjectDependencies.insert(pd);
- int temp = _block->newTemp();
- _block->MOVE(_block->TEMP(temp), _block->NAME(V4IR::Name::builtin_qml_context_object, line, col));
- V4IR::Temp *base = _block->TEMP(temp);
+ V4IR::Temp *base = _block->TEMP(_contextObjectTemp);
initMetaObjectResolver(&base->memberResolver, _contextObject);
return _block->QML_QOBJECT_PROPERTY(base, _function->newString(name), pd);
}
diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h
index 03c69efb80..4f80a7f148 100644
--- a/src/qml/compiler/qqmlcodegenerator_p.h
+++ b/src/qml/compiler/qqmlcodegenerator_p.h
@@ -365,6 +365,7 @@ struct Q_QML_EXPORT JSCodeGen : public QQmlJS::Codegen
QVector<int> generateJSCodeForFunctionsAndBindings(const QList<AST::Node*> &functions, const QHash<int, QString> &functionNames);
protected:
+ virtual void beginFunctionBodyHook();
virtual V4IR::Expr *fallbackNameLookup(const QString &name, int line, int col);
private:
@@ -377,6 +378,10 @@ private:
ObjectIdMapping _idObjects;
QQmlPropertyCache *_contextObject;
QQmlPropertyCache *_scopeObject;
+ int _contextObjectTemp;
+ int _scopeObjectTemp;
+ int _importedScriptsTemp;
+ int _idScopeTemp;
};
} // namespace QtQml
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 893abc9659..a8338f8656 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -2050,6 +2050,8 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast,
ast->firstSourceLocation().startLine, ast->firstSourceLocation().startColumn), 0));
}
+ beginFunctionBodyHook();
+
sourceElements(body);
_function->insertBasicBlock(_exitBlock);
diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h
index 736ac9871d..32f1f1bfd4 100644
--- a/src/qml/compiler/qv4codegen_p.h
+++ b/src/qml/compiler/qv4codegen_p.h
@@ -330,6 +330,7 @@ protected:
V4IR::Expr *identifier(const QString &name, int line = 0, int col = 0);
// Hook provided to implement QML lookup semantics
virtual V4IR::Expr *fallbackNameLookup(const QString &name, int line, int col);
+ virtual void beginFunctionBodyHook() {}
// nodes
virtual bool visit(AST::ArgumentList *ast);