diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-05 13:57:26 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-05-12 15:39:23 +0000 |
commit | 2a992e96f783a8caea3b6a5e8e96d620fcd15817 (patch) | |
tree | fd6809e771ab3a0634db2b72b2e2d5e690128d5c | |
parent | 81943c702ef818003d06c7bccaece2ed23f6079c (diff) |
QML: Port icutils::Node to new special integer bitfield
Change-Id: I46f4f21bda1360d09e2c49a1f04dbe411fb46f7d
Task-number: QTBUG-99545
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit eca5dcab020a60a53c0ad1b130cf2873d3feff3e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qml/inlinecomponentutils_p.h | 49 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4executablecompilationunit.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertycachecreator_p.h | 2 |
3 files changed, 32 insertions, 21 deletions
diff --git a/src/qml/inlinecomponentutils_p.h b/src/qml/inlinecomponentutils_p.h index 74805d6d7c..41333cbb1b 100644 --- a/src/qml/inlinecomponentutils_p.h +++ b/src/qml/inlinecomponentutils_p.h @@ -55,26 +55,38 @@ namespace icutils { struct Node { +private: + using IndexType = std::vector<QV4::CompiledData::InlineComponent>::size_type; + using IndexField = quint32_le_bitfield_member<0, 30, IndexType>; + using TemporaryMarkField = quint32_le_bitfield_member<30, 1>; + using PermanentMarkField = quint32_le_bitfield_member<31, 1>; + quint32_le_bitfield_union<IndexField, TemporaryMarkField, PermanentMarkField> m_data; + +public: Node() = default; Node(const Node &) = default; Node(Node &&) = default; Node& operator=(Node const &) = default; Node& operator=(Node &&) = default; - bool operator==(Node const &other) const {return index == other.index;} + bool operator==(Node const &other) const {return m_data.data() == other.m_data.data(); } + + Node(IndexType s) : m_data(QSpecialIntegerBitfieldZero) { m_data.set<IndexField>(s); } + + bool hasPermanentMark() const { return m_data.get<PermanentMarkField>(); } + bool hasTemporaryMark() const { return m_data.get<TemporaryMarkField>(); } + + void setPermanentMark() + { + m_data.set<TemporaryMarkField>(0); + m_data.set<PermanentMarkField>(1); + } - Node(std::vector<QV4::CompiledData::InlineComponent>::size_type s) - : index{0} + void setTemporaryMark() { - index = quint32(s); - temporaryMark = 0; - permanentMark = 0; + m_data.set<TemporaryMarkField>(1); } - union { - quint32_le_bitfield<0, 30> index; - quint32_le_bitfield<30, 1> temporaryMark; - quint32_le_bitfield<31, 1> permanentMark; - }; + IndexType index() const { return m_data.get<IndexField>(); } }; using AdjacencyList = std::vector<std::vector<Node*>>; @@ -122,21 +134,20 @@ void fillAdjacencyListForInlineComponents(ObjectContainer *objectContainer, Adja }; inline void topoVisit(Node *node, AdjacencyList &adjacencyList, bool &hasCycle, std::vector<Node> &nodesSorted) { - if (node->permanentMark) + if (node->hasPermanentMark()) return; - if (node->temporaryMark) { + if (node->hasTemporaryMark()) { hasCycle = true; return; } - node->temporaryMark = 1; + node->setTemporaryMark(); - auto const &edges = adjacencyList[node->index]; + auto const &edges = adjacencyList[node->index()]; for (auto edgeTarget =edges.begin(); edgeTarget != edges.end(); ++edgeTarget) { topoVisit(*edgeTarget, adjacencyList, hasCycle, nodesSorted); } - node->temporaryMark = 0; - node->permanentMark = 1; + node->setPermanentMark(); nodesSorted.push_back(*node); }; @@ -147,7 +158,7 @@ inline std::vector<Node> topoSort(std::vector<Node> &nodes, AdjacencyList &adjac hasCycle = false; auto currentNodeIt = std::find_if(nodes.begin(), nodes.end(), [](const Node& node) { - return node.permanentMark == 0; + return !node.hasPermanentMark(); }); // Do a topological sort of all inline components // afterwards, nodesSorted contains the nodes for the inline components in reverse topological order @@ -155,7 +166,7 @@ inline std::vector<Node> topoSort(std::vector<Node> &nodes, AdjacencyList &adjac Node& currentNode = *currentNodeIt; topoVisit(¤tNode, adjacencyList, hasCycle, nodesSorted); currentNodeIt = std::find_if(nodes.begin(), nodes.end(), [](const Node& node) { - return node.permanentMark == 0; + return !node.hasPermanentMark(); }); } return nodesSorted; diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp index f015040aa5..dd9a98e11c 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit.cpp +++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp @@ -442,7 +442,7 @@ void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngi // We need to first iterate over all inline components, as the containing component might create instances of them // and in that case we need to add its object count for (auto nodeIt = nodesSorted.rbegin(); nodeIt != nodesSorted.rend(); ++nodeIt) { - const auto &ic = allICs.at(nodeIt->index); + const auto &ic = allICs.at(nodeIt->index()); int lastICRoot = ic.objectIndex; for (int i = ic.objectIndex; i<objectCount(); ++i) { const QV4::CompiledData::Object *obj = objectAt(i); diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index 524e083a6f..bf293a1cd3 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -243,7 +243,7 @@ QQmlPropertyCacheCreator<ObjectContainer>::buildMetaObjectsIncrementally() // create meta objects for inline components before compiling actual root component if (nodeIt != nodesSorted.rend()) { - const auto &ic = allICs[nodeIt->index]; + const auto &ic = allICs[nodeIt->index()]; QV4::ResolvedTypeReference *typeRef = objectContainer->resolvedType(ic.nameIndex); Q_ASSERT(propertyCaches->at(ic.objectIndex) == nullptr); Q_ASSERT(typeRef->typePropertyCache().isNull()); // not set yet |