From 4e5c096153b8a5d6e110ef8a6db265b0bc138ce1 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 8 Jan 2024 13:40:12 +0100 Subject: QtQml: Move type name cache into base CU Change-Id: Ie3504f16b34859cdef72f8138e6058dcc2d1f58f Reviewed-by: Fabian Kosmale --- src/qml/common/qv4compileddata.cpp | 7 +++++++ src/qml/common/qv4compileddata_p.h | 11 +++++------ src/qml/jsruntime/qv4executablecompilationunit.cpp | 2 -- src/qml/jsruntime/qv4executablecompilationunit_p.h | 21 +++++++++++++++------ src/qml/jsruntime/qv4function.cpp | 7 ++++--- src/qml/qml/qqmlengine.cpp | 2 +- src/qml/qml/qqmlobjectcreator.cpp | 2 +- src/qml/qml/qqmltypedata.cpp | 7 ++++--- src/qmltest/quicktest.cpp | 2 +- 9 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/qml/common/qv4compileddata.cpp b/src/qml/common/qv4compileddata.cpp index 6087db9b92..253c9a5e77 100644 --- a/src/qml/common/qv4compileddata.cpp +++ b/src/qml/common/qv4compileddata.cpp @@ -3,6 +3,7 @@ #include "qv4compileddata_p.h" +#include #include #include @@ -39,6 +40,12 @@ bool ResolvedTypeReferenceMap::addToHash( return true; } +CompilationUnit::CompilationUnit( + const Unit *unitData, const QString &fileName, const QString &finalUrlString) +{ + setUnitData(unitData, nullptr, fileName, finalUrlString); +} + CompilationUnit::~CompilationUnit() { qDeleteAll(resolvedTypes); diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h index 7e768cd589..5d4c7747d1 100644 --- a/src/qml/common/qv4compileddata_p.h +++ b/src/qml/common/qv4compileddata_p.h @@ -1487,6 +1487,7 @@ struct CompilationUnit final : public QQmlRefCounted QVector bindingPropertyDataPerObject; ResolvedTypeReferenceMap resolvedTypes; + QQmlRefPointer typeNameCache; QQmlPropertyCacheVector propertyCaches; @@ -1495,12 +1496,6 @@ struct CompilationUnit final : public QQmlRefCounted public: using CompiledObject = CompiledData::Object; - CompilationUnit(const Unit *unitData = nullptr, const QString &fileName = QString(), - const QString &finalUrlString = QString()) - { - setUnitData(unitData, nullptr, fileName, finalUrlString); - } - explicit CompilationUnit(const Unit *unitData, const QQmlPrivate::AOTCompiledFunction *aotCompiledFunctions, const QString &fileName = QString(), const QString &finalUrlString = QString()) : CompilationUnit(unitData, fileName, finalUrlString) @@ -1508,6 +1503,10 @@ public: this->aotCompiledFunctions = aotCompiledFunctions; } + Q_QML_EXPORT CompilationUnit( + const Unit *unitData = nullptr, const QString &fileName = QString(), + const QString &finalUrlString = QString()); + Q_QML_EXPORT ~CompilationUnit(); const Unit *unitData() const { return data; } diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp index efba61b8c9..60af2b2203 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit.cpp +++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp @@ -262,8 +262,6 @@ void ExecutableCompilationUnit::clear() dependentScripts.clear(); - typeNameCache.reset(); - delete [] runtimeLookups; runtimeLookups = nullptr; diff --git a/src/qml/jsruntime/qv4executablecompilationunit_p.h b/src/qml/jsruntime/qv4executablecompilationunit_p.h index b4d3e413c1..3d9b32d354 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit_p.h +++ b/src/qml/jsruntime/qv4executablecompilationunit_p.h @@ -15,14 +15,15 @@ // We mean it. // -#include -#include -#include #include +#include +#include #include +#include #include -#include -#include +#include +#include +#include #include @@ -78,7 +79,15 @@ public: QUrl url() const { return m_compilationUnit->url(); } QUrl finalUrl() const { return m_compilationUnit->finalUrl(); } - QQmlRefPointer typeNameCache; + QQmlRefPointer typeNameCache() const + { + return m_compilationUnit->typeNameCache; + } + + void setTypeNameCache(const QQmlRefPointer &typeNameCache) + { + m_compilationUnit->typeNameCache = typeNameCache; + } const QQmlPropertyCacheVector *propertyCachesPtr() const { diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index 7283565489..2e51366d64 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -148,9 +148,10 @@ Function::Function(ExecutionEngine *engine, ExecutableCompilationUnit *unit, if (type == 0) return QQmlType(); + const auto base = unit->baseCompilationUnit(); const QQmlType qmltype = typeLoader - ? unit->typeNameCache->query( - unit->stringAt(type), typeLoader).type + ? base->typeNameCache->query( + base->stringAt(type), typeLoader).type : QQmlType(); if (!qmltype.isValid() || qmltype.typeId().isValid()) @@ -158,7 +159,7 @@ Function::Function(ExecutionEngine *engine, ExecutableCompilationUnit *unit, if (!qmltype.isComposite()) { return qmltype.isInlineComponentType() - ? unit->qmlTypeForComponent(qmltype.elementName()) + ? base->qmlTypeForComponent(qmltype.elementName()) : QQmlType(); } diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 9fb1e19d6a..49093bfdbd 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1986,7 +1986,7 @@ QQmlEnginePrivate::createInternalContext(const QQmlRefPointer context; context = QQmlContextData::createRefCounted(parentContext); context->setInternal(true); - context->setImports(unit->typeNameCache); + context->setImports(unit->typeNameCache()); context->initFromTypeCompilationUnit(unit, subComponentIndex); if (isComponentRoot && unit->dependentScripts.size()) { diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index e395787acb..31600e234f 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -1367,7 +1367,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo if (customParser && obj->hasFlag(QV4::CompiledData::Object::HasCustomParserBindings)) { customParser->engine = QQmlEnginePrivate::get(engine); - customParser->imports = compilationUnit->typeNameCache.data(); + customParser->imports = compilationUnit->typeNameCache().data(); QList bindings; const QV4::CompiledData::Object *obj = compilationUnit->objectAt(index); diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp index 5a1df833a6..8d66a265d4 100644 --- a/src/qml/qml/qqmltypedata.cpp +++ b/src/qml/qml/qqmltypedata.cpp @@ -239,7 +239,7 @@ QQmlError QQmlTypeData::createTypeAndPropertyCaches( const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache) { Q_ASSERT(m_compiledData); - m_compiledData->typeNameCache = typeNameCache; + m_compiledData->setTypeNameCache(typeNameCache); m_compiledData->setResolvedTypes(resolvedTypeCache); m_compiledData->setInlineComponentData(m_inlineComponentData); @@ -570,7 +570,8 @@ void QQmlTypeData::done() qualifier = qualifier.mid(lastDotIndex+1); } - m_compiledData->typeNameCache->add(qualifier.toString(), scriptIndex, enclosingNamespace); + m_compiledData->typeNameCache()->add( + qualifier.toString(), scriptIndex, enclosingNamespace); QQmlRefPointer scriptData = script.script->scriptData(); m_compiledData->dependentScripts << scriptData; } @@ -848,7 +849,7 @@ void QQmlTypeData::compile(const QQmlRefPointer &typeNameCach m_compiledData = enginePrivate->v4engine()->executableCompilationUnit( std::move(compilationUnit)); - m_compiledData->typeNameCache = typeNameCache; + m_compiledData->setTypeNameCache(typeNameCache); m_compiledData->setResolvedTypes(*resolvedTypeCache); *m_compiledData->propertyCachesPtr() = std::move(*compiler.propertyCaches()); Q_ASSERT(m_compiledData->propertyCachesPtr()->count() diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index d15dd638b0..c762e34a2e 100644 --- a/src/qmltest/quicktest.cpp +++ b/src/qmltest/quicktest.cpp @@ -354,7 +354,7 @@ private: if (!typeQualifier.isEmpty()) testCaseTypeName = typeQualifier % QLatin1Char('.') % testCaseTypeName; - testCaseType = compilationUnit->typeNameCache->query( + testCaseType = compilationUnit->typeNameCache()->query( testCaseTypeName, QQmlTypeLoader::get(m_engine)).type; if (testCaseType.isValid()) break; -- cgit v1.2.3