diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2017-06-23 13:36:13 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2017-08-02 16:32:49 +0000 |
commit | c6b2dd879d02b21b18f80faab541f8f04286685a (patch) | |
tree | cfae0855871c1fa2cd2fcdf21b14af0a392ced93 /src/qml/qml/qqmlmetatype.cpp | |
parent | db1034d093d76b4b6e66fcdd178800e0cf9d1005 (diff) |
Move property cache from the engine to QQmlType
Now that the property cache is independent of a specific
engine, we can cache them in QQmlType instead of caching
them per engine.
This simplifies the logic and avoids duplicated property
caches when multiple engines are running.
Task-number: QTBUG-61536
Change-Id: I6f082e1e7495ae0f5b92559e8d0a3437c56e303a
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 3e29222200..a2b6913943 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -110,6 +110,9 @@ struct QQmlMetaTypeData QString typeRegistrationNamespace; QStringList typeRegistrationFailures; + + QHash<const QMetaObject *, QQmlPropertyCache *> propertyCaches; + QQmlPropertyCache *propertyCache(const QMetaObject *metaObject); }; class QQmlTypeModulePrivate @@ -151,6 +154,9 @@ QQmlMetaTypeData::~QQmlMetaTypeData() for (TypeModules::const_iterator i = uriToModule.constBegin(), cend = uriToModule.constEnd(); i != cend; ++i) delete *i; + for (QHash<const QMetaObject *, QQmlPropertyCache *>::Iterator it = propertyCaches.begin(), end = propertyCaches.end(); + it != end; ++it) + (*it)->release(); } class QQmlTypePrivate @@ -1981,6 +1987,29 @@ QQmlType QQmlMetaType::qmlTypeFromIndex(int idx) return data->types.at(idx); } +QQmlPropertyCache *QQmlMetaTypeData::propertyCache(const QMetaObject *metaObject) +{ + if (QQmlPropertyCache *rv = propertyCaches.value(metaObject)) + return rv; + + if (!metaObject->superClass()) { + QQmlPropertyCache *rv = new QQmlPropertyCache(metaObject); + propertyCaches.insert(metaObject, rv); + return rv; + } + QQmlPropertyCache *super = propertyCache(metaObject->superClass()); + QQmlPropertyCache *rv = super->copyAndAppend(metaObject); + propertyCaches.insert(metaObject, rv); + return rv; +} + +QQmlPropertyCache *QQmlMetaType::propertyCache(const QMetaObject *metaObject) +{ + QMutexLocker lock(metaTypeDataLock()); + QQmlMetaTypeData *data = metaTypeData(); + return data->propertyCache(metaObject); +} + /*! Returns the list of registered QML type names. */ |