From 8248b5a485a2b8885442d6511906526548d9d07e Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 24 Aug 2020 14:10:41 +0200 Subject: Always group the metaType and listType together They are always created and destroyed together, so grouping them makes the required memory management of them easier. Change-Id: Ia1980f31f9bdff6a1accd229bc8380ae153edf67 Reviewed-by: Fabian Kosmale --- src/qml/jsruntime/qv4executablecompilationunit.cpp | 19 ++++++++----------- src/qml/jsruntime/qv4executablecompilationunit_p.h | 3 +-- src/qml/qml/qqmlengine.cpp | 8 ++++---- src/qml/qml/qqmlpropertycachecreator_p.h | 4 ++-- src/qml/qml/qqmltypewrapper.cpp | 2 +- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 6 +++--- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp index 0535e5029f..9d8332ea55 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit.cpp +++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp @@ -302,8 +302,8 @@ void ExecutableCompilationUnit::unlink() Q_ASSERT(data && propertyCaches.count() > 0 && propertyCaches.at(/*root object*/0)); if (qmlEngine) qmlEngine->unregisterInternalCompositeType(this); - QQmlMetaType::unregisterInternalCompositeType({metaTypeId, listMetaTypeId}); isRegisteredWithEngine = false; + QQmlMetaType::unregisterInternalCompositeType(typeIds); } propertyCaches.clear(); @@ -402,17 +402,16 @@ IdentifierHash ExecutableCompilationUnit::createNamedObjectsPerComponent(int com return *namedObjectsPerComponentCache.insert(componentObjectIndex, namedObjectCache); } -void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngine, CompositeMetaTypeIds typeIds) +void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngine, CompositeMetaTypeIds types) { this->qmlEngine = qmlEngine; // Add to type registry of composites if (propertyCaches.needsVMEMetaObject(/*root object*/0)) { // typeIds is only valid for types that have references to themselves. - if (!typeIds.isValid()) - typeIds = QQmlMetaType::registerInternalCompositeType(rootPropertyCache()->className()); - metaTypeId = typeIds.id; - listMetaTypeId = typeIds.listId; + if (!types.isValid()) + types = QQmlMetaType::registerInternalCompositeType(rootPropertyCache()->className()); + typeIds = types; qmlEngine->registerInternalCompositeType(this); } else { @@ -420,12 +419,10 @@ void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngi auto *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex); Q_ASSERT(typeRef); if (const auto compilationUnit = typeRef->compilationUnit()) { - metaTypeId = compilationUnit->metaTypeId; - listMetaTypeId = compilationUnit->listMetaTypeId; + typeIds = compilationUnit->typeIds; } else { const auto type = typeRef->type(); - metaTypeId = type.typeId(); - listMetaTypeId = type.qListTypeId(); + typeIds = CompositeMetaTypeIds{ type.typeId(), type.qListTypeId() }; } } @@ -549,7 +546,7 @@ bool ExecutableCompilationUnit::verifyChecksum(const CompiledData::DependentType CompositeMetaTypeIds ExecutableCompilationUnit::typeIdsForComponent(int objectid) const { if (objectid == 0) - return {metaTypeId, listMetaTypeId}; + return typeIds; return inlineComponentData[objectid].typeIds; } diff --git a/src/qml/jsruntime/qv4executablecompilationunit_p.h b/src/qml/jsruntime/qv4executablecompilationunit_p.h index 1af5824074..1b1b9add5c 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit_p.h +++ b/src/qml/jsruntime/qv4executablecompilationunit_p.h @@ -182,8 +182,7 @@ public: CompositeMetaTypeIds typeIdsForComponent(int objectid = 0) const; - QMetaType metaTypeId; - QMetaType listMetaTypeId; + CompositeMetaTypeIds typeIds; bool isRegisteredWithEngine = false; QHash inlineComponentData; diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index d7cca8e3fc..7191da694d 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -651,7 +651,7 @@ QQmlEnginePrivate::~QQmlEnginePrivate() for (auto iter = m_compositeTypes.cbegin(), end = m_compositeTypes.cend(); iter != end; ++iter) { iter.value()->isRegisteredWithEngine = false; - QQmlMetaType::unregisterInternalCompositeType({iter.value()->metaTypeId, iter.value()->listMetaTypeId}); + QQmlMetaType::unregisterInternalCompositeType(iter.value()->typeIds); } #if QT_CONFIG(qml_debug) delete profiler; @@ -2248,7 +2248,7 @@ int QQmlEnginePrivate::listType(int t) const static QQmlPropertyCache *propertyCacheForPotentialInlineComponentType(int t, const QHash::const_iterator &iter) { - if (t != (*iter)->metaTypeId.id()) { + if (t != (*iter)->typeIds.id.id()) { // this is an inline component, and what we have in the iterator is currently the parent compilation unit for (auto &&icDatum: (*iter)->inlineComponentData) if (icDatum.typeIds.id.id() == t) @@ -2351,7 +2351,7 @@ void QQmlEnginePrivate::registerInternalCompositeType(QV4::ExecutableCompilation Locker locker(this); // The QQmlCompiledData is not referenced here, but it is removed from this // hash in the QQmlCompiledData destructor - m_compositeTypes.insert(compilationUnit->metaTypeId.id(), compilationUnit); + m_compositeTypes.insert(compilationUnit->typeIds.id.id(), compilationUnit); for (auto &&data: compilationUnit->inlineComponentData) m_compositeTypes.insert(data.typeIds.id.id(), compilationUnit); } @@ -2361,7 +2361,7 @@ void QQmlEnginePrivate::unregisterInternalCompositeType(QV4::ExecutableCompilati compilationUnit->isRegisteredWithEngine = false; Locker locker(this); - m_compositeTypes.remove(compilationUnit->metaTypeId.id()); + m_compositeTypes.remove(compilationUnit->typeIds.id.id()); for (auto&& icDatum: compilationUnit->inlineComponentData) m_compositeTypes.remove(icDatum.typeIds.id.id()); } diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index 5c9e806a4e..626b274c2f 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -649,7 +649,7 @@ inline int QQmlPropertyCacheCreator::metaTypeForParameter(const auto compilationUnit = tdata->compilationUnit(); - return compilationUnit->metaTypeId.id(); + return compilationUnit->typeIds.id.id(); } template @@ -834,7 +834,7 @@ inline QQmlError QQmlPropertyCacheAliasCreator::propertyDataFor if (referencedType.isValid()) *type = referencedType.typeId().id(); else - *type = typeRef->compilationUnit()->metaTypeId.id(); + *type = typeRef->compilationUnit()->typeIds.id.id(); *version = typeRef->version(); diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 6258403f33..495822251f 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -397,7 +397,7 @@ ReturnedValue QQmlTypeWrapper::virtualInstanceOf(const Object *typeObject, const QQmlRefPointer td = qenginepriv->typeLoader.getType(typeWrapper->d()->type().sourceUrl()); ExecutableCompilationUnit *cu = td->compilationUnit(); - myQmlType = qenginepriv->metaObjectForType(cu->metaTypeId.id()); + myQmlType = qenginepriv->metaObjectForType(cu->typeIds.id.id()); } else { myQmlType = qenginepriv->metaObjectForType(myTypeId.id()); } diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 2932b112e3..fe14964b7e 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -5483,7 +5483,7 @@ void tst_qqmllanguage::selfReference() const QMetaObject *metaObject = o->metaObject(); QMetaProperty selfProperty = metaObject->property(metaObject->indexOfProperty("self")); - QCOMPARE(selfProperty.userType(), compilationUnit->metaTypeId.id()); + QCOMPARE(selfProperty.userType(), compilationUnit->typeIds.id.id()); QByteArray typeName = selfProperty.typeName(); QVERIFY(typeName.endsWith('*')); @@ -5492,7 +5492,7 @@ void tst_qqmllanguage::selfReference() QMetaMethod selfFunction = metaObject->method(metaObject->indexOfMethod("returnSelf()")); QVERIFY(selfFunction.isValid()); - QCOMPARE(selfFunction.returnType(), compilationUnit->metaTypeId.id()); + QCOMPARE(selfFunction.returnType(), compilationUnit->typeIds.id.id()); QMetaMethod selfSignal; @@ -5506,7 +5506,7 @@ void tst_qqmllanguage::selfReference() QVERIFY(selfSignal.isValid()); QCOMPARE(selfSignal.parameterCount(), 1); - QCOMPARE(selfSignal.parameterType(0), compilationUnit->metaTypeId.id()); + QCOMPARE(selfSignal.parameterType(0), compilationUnit->typeIds.id.id()); } void tst_qqmllanguage::selfReferencingSingleton() -- cgit v1.2.3