From 777aac3005feb01aed21df9e135d5470182bc6ce Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 26 May 2016 11:17:31 +0200 Subject: [PATCH] Small type compilation data structure cleanup After the removal of the named object hash tables in the persistent compilation unit data, we can also eliminate them from the temporary internal type compilation structures. We have everything we need in the object naming table in the CompiledData::Object - the only thing missing are the component roots. Change-Id: Ia2a7b3894310cfdb5cfecf1c2a921fb51e2a883b Reviewed-by: Lars Knoll --- src/qml/compiler/qqmlirbuilder_p.h | 10 +++++++ src/qml/compiler/qqmltypecompiler.cpp | 41 ++++++++------------------- src/qml/compiler/qqmltypecompiler_p.h | 14 ++++----- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h index 16dcd70554..db17c93222 100644 --- a/src/qml/compiler/qqmlirbuilder_p.h +++ b/src/qml/compiler/qqmlirbuilder_p.h @@ -188,6 +188,16 @@ public: } } + template + void allocate(QQmlJS::MemoryPool *pool, const Container &container) + { + count = container.count(); + data = reinterpret_cast(pool->allocate(count * sizeof(T))); + typename Container::ConstIterator it = container.constBegin(); + for (int i = 0; i < count; ++i) + new (data + i) T(*it++); + } + const T &at(int index) const { Q_ASSERT(index >= 0 && index < count); return data[index]; diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 3e63e4246f..124541b63b 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -346,16 +346,6 @@ const QQmlPropertyCacheVector &QQmlTypeCompiler::propertyCaches() const return compiledData->propertyCaches; } -QVector *QQmlTypeCompiler::namedObjectsInRootScope() -{ - return &m_namedObjectsInRootScope; -} - -QHash> *QQmlTypeCompiler::namedObjectsPerComponent() -{ - return &m_namedObjectsPerComponent; -} - QHash *QQmlTypeCompiler::customParserBindings() { return &compiledData->customParserBindings; @@ -1324,11 +1314,8 @@ QQmlComponentAndAliasResolver::QQmlComponentAndAliasResolver(QQmlTypeCompiler *t , qmlObjects(typeCompiler->qmlObjects()) , indexOfRootObject(typeCompiler->rootObjectIndex()) , _componentIndex(-1) - , _namedObjectsInScope(0) , resolvedTypes(typeCompiler->resolvedTypes()) , propertyCaches(typeCompiler->propertyCaches()) - , namedObjectsInRootScope(typeCompiler->namedObjectsInRootScope()) - , namedObjectsPerComponent(typeCompiler->namedObjectsPerComponent()) { } @@ -1475,8 +1462,6 @@ bool QQmlComponentAndAliasResolver::resolve() _componentIndex = i; _idToObjectIndex.clear(); - _namedObjectsInScope = &(*namedObjectsPerComponent)[componentRoots.at(i)]; - _objectsWithAliases.clear(); if (!collectIdsAndAliases(rootBinding->value.objectIndex)) @@ -1485,13 +1470,12 @@ bool QQmlComponentAndAliasResolver::resolve() if (!resolveAliases()) return false; - component->namedObjectsInComponent.allocate(pool, *_namedObjectsInScope); + component->namedObjectsInComponent.allocate(pool, _idToObjectIndex); } // Collect ids and aliases for root _componentIndex = -1; _idToObjectIndex.clear(); - _namedObjectsInScope = namedObjectsInRootScope; _objectsWithAliases.clear(); collectIdsAndAliases(indexOfRootObject); @@ -1499,11 +1483,12 @@ bool QQmlComponentAndAliasResolver::resolve() resolveAliases(); QmlIR::Object *rootComponent = qmlObjects->at(indexOfRootObject); - rootComponent->namedObjectsInComponent.allocate(pool, *_namedObjectsInScope); + rootComponent->namedObjectsInComponent.allocate(pool, _idToObjectIndex); // Implicit component insertion may have added objects and thus we also need // to extend the symmetric propertyCaches. compiler->setPropertyCaches(propertyCaches); + compiler->setComponentRoots(componentRoots); return true; } @@ -1517,9 +1502,8 @@ bool QQmlComponentAndAliasResolver::collectIdsAndAliases(int objectIndex) recordError(obj->locationOfIdProperty, tr("id is not unique")); return false; } + obj->id = _idToObjectIndex.count(); _idToObjectIndex.insert(obj->idNameIndex, objectIndex); - obj->id = _namedObjectsInScope->count(); - _namedObjectsInScope->append(objectIndex); } if (obj->aliasCount() > 0) @@ -2383,17 +2367,16 @@ QQmlJSCodeGenerator::QQmlJSCodeGenerator(QQmlTypeCompiler *typeCompiler, QmlIR:: bool QQmlJSCodeGenerator::generateCodeForComponents() { - const QHash> &namedObjectsPerComponent = *compiler->namedObjectsPerComponent(); - for (QHash>::ConstIterator component = namedObjectsPerComponent.constBegin(), end = namedObjectsPerComponent.constEnd(); - component != end; ++component) { - if (!compileComponent(component.key(), component.value())) + const QVector &componentRoots = compiler->componentRoots(); + for (int i = 0; i < componentRoots.count(); ++i) { + if (!compileComponent(componentRoots.at(i))) return false; } - return compileComponent(compiler->rootObjectIndex(), *compiler->namedObjectsInRootScope()); + return compileComponent(compiler->rootObjectIndex()); } -bool QQmlJSCodeGenerator::compileComponent(int contextObject, const QVector &namedObjects) +bool QQmlJSCodeGenerator::compileComponent(int contextObject) { const QmlIR::Object *obj = qmlObjects.at(contextObject); if (obj->flags & QV4::CompiledData::Object::IsComponent) { @@ -2404,9 +2387,9 @@ bool QQmlJSCodeGenerator::compileComponent(int contextObject, const QVectornamedObjectsInComponent.count); + for (int i = 0; i < obj->namedObjectsInComponent.count; ++i) { + const int objectIndex = obj->namedObjectsInComponent.at(i); QmlIR::JSCodeGen::IdMapping m; const QmlIR::Object *obj = qmlObjects.at(objectIndex); m.name = stringAt(obj->idNameIndex); diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h index 2b84bc7ebe..5fbc1d370a 100644 --- a/src/qml/compiler/qqmltypecompiler_p.h +++ b/src/qml/compiler/qqmltypecompiler_p.h @@ -101,8 +101,8 @@ public: int rootObjectIndex() const; void setPropertyCaches(const QQmlPropertyCacheVector &caches); const QQmlPropertyCacheVector &propertyCaches() const; - QVector *namedObjectsInRootScope(); - QHash > *namedObjectsPerComponent(); + void setComponentRoots(const QVector &roots) { m_componentRoots = roots; } + const QVector &componentRoots() const { return m_componentRoots; } QHash *customParserBindings(); QQmlJS::MemoryPool *memoryPool(); QStringRef newStringRef(const QString &string); @@ -124,8 +124,7 @@ private: QHash customParsers; // index in first hash is component index, vector inside contains object indices of objects with id property - QHash> m_namedObjectsPerComponent; - QVector m_namedObjectsInRootScope; + QVector m_componentRoots; }; struct QQmlCompilePass @@ -272,17 +271,14 @@ protected: const int indexOfRootObject; // indices of the objects that are actually Component {} - QVector componentRoots; + QVector componentRoots; int _componentIndex; QHash _idToObjectIndex; - QVector *_namedObjectsInScope; QList _objectsWithAliases; QHash *resolvedTypes; QQmlPropertyCacheVector propertyCaches; - QVector *namedObjectsInRootScope; - QHash> *namedObjectsPerComponent; }; class QQmlPropertyValidator : public QQmlCompilePass @@ -325,7 +321,7 @@ public: bool generateCodeForComponents(); private: - bool compileComponent(int componentRoot, const QVector &namedObjects); + bool compileComponent(int componentRoot); bool compileJavaScriptCodeInObjectsRecursively(int objectIndex, int scopeObjectIndex); const QHash &resolvedTypes;