Reduce dependencies on QQmlValueType being a QObject
authorSimon Hausmann <simon.hausmann@theqtcompany.com>
Tue, 18 Nov 2014 18:21:07 +0000 (19:21 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 23 Dec 2014 13:50:55 +0000 (14:50 +0100)
Don't rely on caching the property cache in the QQmlData of the value type,
instead we can cache is in the engine and store it in our object data.

Change-Id: I5f31313c066cd7918caf33e3fabdf5aac71f1adb
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/qqmlvaluetypewrapper.cpp
src/qml/qml/qqmlvaluetypewrapper_p.h

index b4f0cde..72a16a6 100644 (file)
@@ -108,9 +108,13 @@ bool QQmlValueTypeReference::readReferenceValue() const
             // possible, or return false if it is not a value type.
             if (QQmlValueTypeFactory::isValueType(variantReferenceType)) {
                 QQmlValueType *vt = 0;
-                if (const QMetaObject *mo = QQmlValueTypeFactory::metaObjectForMetaType(variantReferenceType))
+                QQmlPropertyCache *cache = 0;
+                if (const QMetaObject *mo = QQmlValueTypeFactory::metaObjectForMetaType(variantReferenceType)) {
                     vt = new QQmlValueType(variantReferenceType, mo);
+                    cache = QQmlEnginePrivate::get(engine())->cache(mo);
+                }
                 d()->type.reset(vt);
+                d()->propertyCache = cache;
                 if (!d()->type) {
                     return false;
                 }
@@ -146,6 +150,7 @@ ReturnedValue QQmlValueTypeWrapper::create(ExecutionEngine *engine, QObject *obj
     ScopedObject proto(scope, engine->qmlExtensions()->valueTypeWrapperPrototype);
     r->setPrototype(proto);
     r->d()->type.reset(new QQmlValueType(typeId, metaObject)); r->d()->object = object; r->d()->property = property;
+    r->d()->propertyCache = QQmlEnginePrivate::get(engine)->cache(metaObject);
     return r->asReturnedValue();
 }
 
@@ -158,6 +163,7 @@ ReturnedValue QQmlValueTypeWrapper::create(ExecutionEngine *engine, const QVaria
     ScopedObject proto(scope, engine->qmlExtensions()->valueTypeWrapperPrototype);
     r->setPrototype(proto);
     r->d()->type.reset(new QQmlValueType(typeId, metaObject)); r->d()->type->setValue(value);
+    r->d()->propertyCache = QQmlEnginePrivate::get(engine)->cache(metaObject);
     return r->asReturnedValue();
 }
 
@@ -194,17 +200,7 @@ PropertyAttributes QQmlValueTypeWrapper::query(const Managed *m, String *name)
     Q_ASSERT(m->as<const QQmlValueTypeWrapper>());
     const QQmlValueTypeWrapper *r = static_cast<const QQmlValueTypeWrapper *>(m);
 
-    QQmlPropertyData local;
-    QQmlPropertyData *result = 0;
-    {
-        QQmlData *ddata = QQmlData::get(r->d()->type.data(), false);
-        if (ddata && ddata->propertyCache)
-            result = ddata->propertyCache->property(name, 0, 0);
-        else {
-            QQmlEngine *engine = qobject_cast<QQmlEngine*>(r->engine()->v8Engine->publicEngine());
-            result = QQmlPropertyCache::property(engine, r->d()->type.data(), name, 0, local);
-        }
-    }
+    QQmlPropertyData *result = r->d()->propertyCache->property(name, 0, 0);
     return result ? Attr_Data : Attr_Invalid;
 }
 
@@ -249,18 +245,7 @@ ReturnedValue QQmlValueTypeWrapper::get(Managed *m, String *name, bool *hasPrope
             return Primitive::undefinedValue().asReturnedValue();
     }
 
-    QQmlPropertyData local;
-    QQmlPropertyData *result = 0;
-    {
-        QQmlData *ddata = QQmlData::get(r->d()->type.data(), false);
-        if (ddata && ddata->propertyCache)
-            result = ddata->propertyCache->property(name, 0, 0);
-        else {
-            QQmlEngine *engine = qobject_cast<QQmlEngine*>(r->engine()->v8Engine->publicEngine());
-            result = QQmlPropertyCache::property(engine, r->d()->type.data(), name, 0, local);
-        }
-    }
-
+    QQmlPropertyData *result = r->d()->propertyCache->property(name, 0, 0);
     if (!result)
         return Object::get(m, name, hasProperty);
 
index b729997..2403180 100644 (file)
@@ -62,6 +62,7 @@ namespace Heap {
 
 struct QQmlValueTypeWrapper : Object {
     QQmlValueTypeWrapper(ExecutionEngine *engine);
+    mutable QQmlRefPointer<QQmlPropertyCache> propertyCache;
     mutable QScopedPointer<QQmlValueType> type;
 };