diff options
author | Lars Knoll <lars.knoll@qt.io> | 2016-12-02 15:19:45 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2016-12-09 14:01:49 +0000 |
commit | c953f8b550b7ea9e7989f9fddaaa14324354aea3 (patch) | |
tree | 02ec1179f225e7b8080136e9e9afc8d6da7fcc32 /src/qml/qml | |
parent | 421d21a0334002f6497ce105876856dc0647c8ff (diff) |
Avoid the creation of a FunctionObject for most bindings
Change-Id: Ia62d380945250015009d9c2b6ed65f6d830277ef
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlbinding.cpp | 15 | ||||
-rw-r--r-- | src/qml/qml/qqmlbinding_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression.cpp | 9 | ||||
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression_p.h | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 6 |
5 files changed, 30 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index a8232904fe..aabdf00f6e 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -123,6 +123,21 @@ QQmlBinding *QQmlBinding::create(const QQmlPropertyData *property, const QV4::Fu return b; } +QQmlBinding *QQmlBinding::create(const QQmlPropertyData *property, QV4::Function *function, + QObject *obj, QQmlContextData *ctxt, QV4::QmlContext *sharedContext) +{ + QQmlBinding *b = newBinding(QQmlEnginePrivate::get(ctxt), property); + + b->setNotifyOnValueChanged(true); + b->QQmlJavaScriptExpression::setContext(ctxt); + b->setScopeObject(obj); + + Q_ASSERT(sharedContext); + b->setupFunction(sharedContext, function); + + return b; +} + QQmlBinding::~QQmlBinding() { } diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h index 23ad06b8c2..889f2ad0af 100644 --- a/src/qml/qml/qqmlbinding_p.h +++ b/src/qml/qml/qqmlbinding_p.h @@ -76,6 +76,8 @@ public: static QQmlBinding *create(const QQmlPropertyData *, const QString &, QObject *, QQmlContextData *, const QString &url = QString(), quint16 lineNumber = 0); static QQmlBinding *create(const QQmlPropertyData *, const QV4::FunctionObject *function, QObject *, QQmlContextData *); + static QQmlBinding *create(const QQmlPropertyData *property, QV4::Function *function, + QObject *obj, QQmlContextData *ctxt, QV4::QmlContext *sharedContext); ~QQmlBinding(); void setTarget(const QQmlProperty &); diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index dc7c1cb8e1..5c6c0a0dce 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -467,6 +467,15 @@ void QQmlJavaScriptExpression::setFunctionObject(const QV4::FunctionObject *o) m_compilationUnit = m_v4Function->compilationUnit; } +void QQmlJavaScriptExpression::setupFunction(QV4::QmlContext *qmlContext, QV4::Function *f) +{ + if (!qmlContext || !f) + return; + m_qmlScope.set(qmlContext->engine(), *qmlContext); + m_v4Function = f; + m_compilationUnit = m_v4Function->compilationUnit; +} + void QQmlJavaScriptExpression::clearActiveGuards() { while (QQmlJavaScriptExpressionGuard *g = activeGuards.takeFirst()) diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index 36024082c9..8a230efeeb 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -159,6 +159,7 @@ protected: } void setFunctionObject(const QV4::FunctionObject *o); + void setupFunction(QV4::QmlContext *qmlContext, QV4::Function *f); private: friend class QQmlContextData; diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index ba3c6600b8..be6a197414 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -792,10 +792,10 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex]; QV4::Scope scope(v4); - QV4::ScopedContext qmlContext(scope, currentQmlContext()); - QV4::ScopedFunctionObject function(scope, QV4::FunctionObject::createScriptFunction(qmlContext, runtimeFunction, /*createProto*/ false)); + QV4::Scoped<QV4::QmlContext> qmlContext(scope, currentQmlContext()); if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression) { + QV4::ScopedFunctionObject function(scope, QV4::FunctionObject::createScriptFunction(qmlContext, runtimeFunction, /*createProto*/ false)); int signalIndex = _propertyCache->methodIndexToSignalIndex(property->coreIndex()); QQmlBoundSignal *bs = new QQmlBoundSignal(_bindingTarget, signalIndex, _scopeObject, engine); QQmlBoundSignalExpression *expr = new QQmlBoundSignalExpression(_bindingTarget, signalIndex, @@ -815,7 +815,7 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con prop = _valueTypeProperty; subprop = property; } - qmlBinding = QQmlBinding::create(prop, function, _scopeObject, context); + qmlBinding = QQmlBinding::create(prop, runtimeFunction, _scopeObject, context, qmlContext); qmlBinding->setTarget(_bindingTarget, *prop, subprop); sharedState->allCreatedBindings.push(QQmlAbstractBinding::Ptr(qmlBinding)); |