diff options
| author | Fabian Kosmale <fabian.kosmale@qt.io> | 2024-11-22 15:03:48 +0100 |
|---|---|---|
| committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2024-12-04 21:26:24 +0100 |
| commit | 84835c51f335acf15982d987cd4486479c1719eb (patch) | |
| tree | 1d9923423c94d9f705ff29338d7510c4a4e7fd96 /src/qml/common/qv4compileddata.cpp | |
| parent | cb0ae6730f66639eb8447f74d76824ed77ad4421 (diff) | |
Move inlineComponentName from CU to ObjectCreator
A (base) compilation unit should ideally be immutable, as we otherwise
open a can of worms when it comes to cross-thread usage of CUs. However,
so far, we've been using a mutable inlineComponentName member of the
compilation unit to select whether the root component of a CU should be
constructed, or one of its inline components.
This patch change prepares for making the CU immutable, by moving the
inline component name tracking into the ObjectCreator itself, requiring
that the name gets passed into its constructor – or that an empty string
gets passed in case of the main component.
The resulting refactoring makes it apparent that deferred properties
did not handle inline components at all. Support for them gets added by
also storing the inline component name inside of DeferredData, and
passing it along when needed. A test case which verifies that deferred
properties are now fixed is added as a follow-up commit.
Besides the core engine, we also need to adjust qmltc which also
generates code to handle deferred properties. Consequently, we also need
to pass the inline component name along in the qmltc generated code.
Task-number: QTBUG-131442
Pick-to: 6.5 6.8
Change-Id: Ide9bc98223c01225b954662b3f4989bbbfda7672
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/common/qv4compileddata.cpp')
| -rw-r--r-- | src/qml/common/qv4compileddata.cpp | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/src/qml/common/qv4compileddata.cpp b/src/qml/common/qv4compileddata.cpp index 9dee91f713..80b806ec2d 100644 --- a/src/qml/common/qv4compileddata.cpp +++ b/src/qml/common/qv4compileddata.cpp @@ -14,6 +14,7 @@ #include <QtCore/qdir.h> #include <QtCore/qscopeguard.h> #include <QtCore/qstandardpaths.h> +#include <QtCore/qxpfunctional.h> static_assert(QV4::CompiledData::QmlCompileHashSpace > QML_COMPILE_HASH_LENGTH); @@ -245,44 +246,30 @@ ResolvedTypeReference *CompilationUnit::resolvedType(QMetaType type) const } -int CompilationUnit::totalBindingsCount() const +int CompilationUnit::totalBindingsCount(const QString &inlineComponentRootName) const { - if (!icRootName) + if (inlineComponentRootName.isEmpty()) return m_totalBindingsCount; - return inlineComponentData[*icRootName].totalBindingCount; + return inlineComponentData[inlineComponentRootName].totalBindingCount; } -int CompilationUnit::totalObjectCount() const +int CompilationUnit::totalObjectCount(const QString &inlineComponentRootName) const { - if (!icRootName) + if (inlineComponentRootName.isEmpty()) return m_totalObjectCount; - return inlineComponentData[*icRootName].totalObjectCount; + return inlineComponentData[inlineComponentRootName].totalObjectCount; } -template<typename F> -void processInlinComponentType( + +static void processInlinComponentType( const QQmlType &type, - const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit, - F &&populateIcData) + qxp::function_ref<void(const QString&)> &&populateIcData) { + QString icRootName; if (type.isInlineComponentType()) { - QString icRootName; - if (compilationUnit->icRootName) { - icRootName = type.elementName(); - std::swap(*compilationUnit->icRootName, icRootName); - } else { - compilationUnit->icRootName = std::make_unique<QString>(type.elementName()); - } - - populateIcData(); - - if (icRootName.isEmpty()) - compilationUnit->icRootName.reset(); - else - std::swap(*compilationUnit->icRootName, icRootName); - } else { - populateIcData(); + icRootName = type.elementName(); } + populateIcData(icRootName); } void CompiledData::CompilationUnit::finalizeCompositeType(const QQmlType &type) @@ -357,11 +344,11 @@ void CompiledData::CompilationUnit::finalizeCompositeType(const QQmlType &type) // if the type is an inline component type, we have to extract the information // from it. // This requires that inline components are visited in the correct order. - processInlinComponentType(type, compilationUnit, [&]() { + processInlinComponentType(type, [&](const QString ¤tlyVisitedICName) { auto &icData = inlineComponentData[lastICRootName]; - icData.totalBindingCount += compilationUnit->totalBindingsCount(); - icData.totalParserStatusCount += compilationUnit->totalParserStatusCount(); - icData.totalObjectCount += compilationUnit->totalObjectCount(); + icData.totalBindingCount += compilationUnit->totalBindingsCount(currentlyVisitedICName); + icData.totalParserStatusCount += compilationUnit->totalParserStatusCount(currentlyVisitedICName); + icData.totalObjectCount += compilationUnit->totalObjectCount(currentlyVisitedICName); }); } } @@ -382,10 +369,10 @@ void CompiledData::CompilationUnit::finalizeCompositeType(const QQmlType &type) ++parserStatusCount; ++objectCount; if (const auto compilationUnit = typeRef->compilationUnit()) { - processInlinComponentType(type, compilationUnit, [&](){ - bindingCount += compilationUnit->totalBindingsCount(); - parserStatusCount += compilationUnit->totalParserStatusCount(); - objectCount += compilationUnit->totalObjectCount(); + processInlinComponentType(type, [&](const QString ¤tlyVisitedICName){ + bindingCount += compilationUnit->totalBindingsCount(currentlyVisitedICName); + parserStatusCount += compilationUnit->totalParserStatusCount(currentlyVisitedICName); + objectCount += compilationUnit->totalObjectCount(currentlyVisitedICName); }); } } @@ -396,11 +383,11 @@ void CompiledData::CompilationUnit::finalizeCompositeType(const QQmlType &type) m_totalObjectCount = objectCount; } -int CompilationUnit::totalParserStatusCount() const +int CompilationUnit::totalParserStatusCount(const QString &inlineComponentRootName) const { - if (!icRootName) + if (inlineComponentRootName.isEmpty()) return m_totalParserStatusCount; - return inlineComponentData[*icRootName].totalParserStatusCount; + return inlineComponentData[inlineComponentRootName].totalParserStatusCount; } bool CompilationUnit::verifyChecksum(const DependentTypesHasher &dependencyHasher) const |
