Create less BindingWrappers
authorLars Knoll <lars.knoll@theqtcompany.com>
Fri, 14 Aug 2015 07:20:42 +0000 (09:20 +0200)
committerSimon Hausmann <simon.hausmann@theqtcompany.com>
Tue, 25 Aug 2015 03:45:49 +0000 (03:45 +0000)
Instead create QmlContext's directly as they are the only
thing used from the binding wrapper.

Change-Id: If3a987134dee9e85b6a76ed74aacd76b19279117
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/jsruntime/qv4script.cpp
src/qml/jsruntime/qv4script_p.h
src/qml/qml/qqmlobjectcreator.cpp
src/qml/qml/qqmlobjectcreator_p.h

index 14b8b878bdb6c8b405e76acfe07b9426b0d551a6..7067d10e222e44ba0f3043068a0668dca176f8e2 100644 (file)
@@ -104,18 +104,6 @@ Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Functio
     internalClass->engine->popContext();
 }
 
-Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::QmlContextWrapper *qml)
-    : Heap::FunctionObject(scope, scope->d()->engine->id_eval(), /*createProto = */ false)
-{
-    Q_ASSERT(scope->inUse());
-
-    Scope s(scope);
-    Scoped<QV4::QmlBindingWrapper> protectThis(s, this);
-
-    this->scope = scope->newQmlContext(qml);
-    internalClass->engine->popContext();
-}
-
 ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData)
 {
     const QmlBindingWrapper *This = static_cast<const QmlBindingWrapper *>(that);
@@ -152,8 +140,8 @@ Heap::FunctionObject *QmlBindingWrapper::createQmlCallableForFunction(QQmlContex
     QV4::Scope valueScope(engine);
     QV4::Scoped<QmlContextWrapper> qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine, qmlContext, scopeObject));
     ScopedContext global(valueScope, valueScope.engine->rootContext());
-    QV4::Scoped<QV4::QmlBindingWrapper> wrapper(valueScope, engine->memoryManager->alloc<QV4::QmlBindingWrapper>(global, qmlScopeObject));
-    QV4::Scoped<QmlContext> wrapperContext(valueScope, wrapper->context());
+    QV4::Scoped<QmlContext> wrapperContext(valueScope, global->newQmlContext(qmlScopeObject));
+    engine->popContext();
 
     if (!signalParameters.isEmpty()) {
         if (error)
index 22714496f8b2a129997b758f26e89499af8fec50..fad011f88aa164b67688d1afdfb6421bf5ec1956 100644 (file)
@@ -88,8 +88,6 @@ struct ContextStateSaver {
 namespace Heap {
 struct QmlBindingWrapper : Heap::FunctionObject {
     QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::QmlContextWrapper *qml);
-    // Constructor for QML functions and signal handlers, resulting binding wrapper is not callable!
-    QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::QmlContextWrapper *qml);
 };
 
 }
@@ -99,8 +97,6 @@ struct Q_QML_EXPORT QmlBindingWrapper : FunctionObject {
 
     static ReturnedValue call(const Managed *that, CallData *callData);
 
-    Heap::QmlContext *context() const { return static_cast<Heap::QmlContext *>(d()->scope.ptr); }
-
     static Heap::FunctionObject *createQmlCallableForFunction(QQmlContextData *qmlContext, QObject *scopeObject, QV4::Function *runtimeFunction,
                                                               const QList<QByteArray> &signalParameters = QList<QByteArray>(), QString *error = 0);
 };
index 0b977f25518f15b0c2049116403d20f6c0b54029..b55973cdc86f90a6302dfd3715849ec5a68bb9d5 100644 (file)
@@ -120,7 +120,7 @@ void QQmlObjectCreator::init(QQmlContextData *providedParentContext)
     _ddata = 0;
     _propertyCache = 0;
     _vmeMetaObject = 0;
-    _qmlBindingWrapper = 0;
+    _qmlContext = 0;
 }
 
 QQmlObjectCreator::~QQmlObjectCreator()
@@ -236,9 +236,9 @@ bool QQmlObjectCreator::populateDeferredProperties(QObject *instance)
     Q_ASSERT(!sharedState->allJavaScriptObjects);
     sharedState->allJavaScriptObjects = valueScope.alloc(compiledData->totalObjectCount);
 
-    QV4::Value *qmlBindingWrapper = valueScope.alloc(1);
+    QV4::QmlContext *qmlContext = static_cast<QV4::QmlContext *>(valueScope.alloc(1));
 
-    qSwap(_qmlBindingWrapper, qmlBindingWrapper);
+    qSwap(_qmlContext, qmlContext);
 
     qSwap(_propertyCache, cache);
     qSwap(_qobject, instance);
@@ -267,7 +267,7 @@ bool QQmlObjectCreator::populateDeferredProperties(QObject *instance)
     qSwap(_qobject, instance);
     qSwap(_propertyCache, cache);
 
-    qSwap(_qmlBindingWrapper, qmlBindingWrapper);
+    qSwap(_qmlContext, qmlContext);
     qSwap(_scopeObject, scopeObject);
 
     phase = ObjectsCreated;
@@ -985,15 +985,16 @@ void QQmlObjectCreator::registerObjectWithContextById(int objectIndex, QObject *
         context->setIdProperty(idEntry.value(), instance);
 }
 
-QV4::Heap::ExecutionContext *QQmlObjectCreator::currentQmlContext()
+QV4::Heap::QmlContext *QQmlObjectCreator::currentQmlContext()
 {
-    if (!_qmlBindingWrapper->objectValue()) {
+    if (!_qmlContext->objectValue()) {
         QV4::Scope valueScope(v4);
         QV4::Scoped<QV4::QmlContextWrapper> qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(v4, context, _scopeObject));
         QV4::ScopedContext global(valueScope, v4->rootContext());
-        *_qmlBindingWrapper = v4->memoryManager->alloc<QV4::QmlBindingWrapper>(global, qmlScope);
+        _qmlContext->setM(global->newQmlContext(qmlScope));
+        v4->popContext();
     }
-    return static_cast<QV4::QmlBindingWrapper*>(_qmlBindingWrapper->objectValue())->context();
+    return _qmlContext->d();
 }
 
 QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isContextObject)
@@ -1140,13 +1141,13 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo
     ++sharedState->allJavaScriptObjects;
 
     QV4::Scope valueScope(v4);
-    QV4::Value *qmlBindingWrapper = valueScope.alloc(1);
+    QV4::QmlContext *qmlContext = static_cast<QV4::QmlContext *>(valueScope.alloc(1));
 
-    qSwap(_qmlBindingWrapper, qmlBindingWrapper);
+    qSwap(_qmlContext, qmlContext);
 
     bool result = populateInstance(index, instance, /*binding target*/instance, /*value type property*/0, bindingsToSkip);
 
-    qSwap(_qmlBindingWrapper, qmlBindingWrapper);
+    qSwap(_qmlContext, qmlContext);
     qSwap(_scopeObject, scopeObject);
 
     return result ? instance : 0;
index c88c15b5252b8527a63233de7e4bf611d95992e6..433bbf5bf2b5c774f5c8a608e18c315a40abbd58 100644 (file)
@@ -107,7 +107,7 @@ private:
 
     void registerObjectWithContextById(int objectIndex, QObject *instance) const;
 
-    QV4::Heap::ExecutionContext *currentQmlContext();
+    QV4::Heap::QmlContext *currentQmlContext();
 
     enum Phase {
         Startup,
@@ -143,7 +143,7 @@ private:
     QQmlRefPointer<QQmlPropertyCache> _propertyCache;
     QQmlVMEMetaObject *_vmeMetaObject;
     QQmlListProperty<void> _currentList;
-    QV4::Value *_qmlBindingWrapper;
+    QV4::QmlContext *_qmlContext;
 
     friend struct QQmlObjectCreatorRecursionWatcher;
 };