aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2016-05-26 11:17:31 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-05-26 19:58:11 +0000
commit777aac3005feb01aed21df9e135d5470182bc6ce (patch)
treeec4b36e1fca9ffda5b28292ac3f562729791ef3e /src
parent18f96551629346599e0b74c3d093697ef494819a (diff)
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 <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qqmlirbuilder_p.h10
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp41
-rw-r--r--src/qml/compiler/qqmltypecompiler_p.h14
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 <typename Container>
+ void allocate(QQmlJS::MemoryPool *pool, const Container &container)
+ {
+ count = container.count();
+ data = reinterpret_cast<T*>(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<quint32> *QQmlTypeCompiler::namedObjectsInRootScope()
-{
- return &m_namedObjectsInRootScope;
-}
-
-QHash<int, QVector<quint32>> *QQmlTypeCompiler::namedObjectsPerComponent()
-{
- return &m_namedObjectsPerComponent;
-}
-
QHash<int, QBitArray> *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<int, QVector<quint32>> &namedObjectsPerComponent = *compiler->namedObjectsPerComponent();
- for (QHash<int, QVector<quint32>>::ConstIterator component = namedObjectsPerComponent.constBegin(), end = namedObjectsPerComponent.constEnd();
- component != end; ++component) {
- if (!compileComponent(component.key(), component.value()))
+ const QVector<quint32> &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<quint32> &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 QVector<quin
}
QmlIR::JSCodeGen::ObjectIdMapping idMapping;
- idMapping.reserve(namedObjects.count());
- for (int i = 0; i < namedObjects.count(); ++i) {
- const int objectIndex = namedObjects.at(i);
+ idMapping.reserve(obj->namedObjectsInComponent.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<quint32> *namedObjectsInRootScope();
- QHash<int, QVector<quint32> > *namedObjectsPerComponent();
+ void setComponentRoots(const QVector<quint32> &roots) { m_componentRoots = roots; }
+ const QVector<quint32> &componentRoots() const { return m_componentRoots; }
QHash<int, QBitArray> *customParserBindings();
QQmlJS::MemoryPool *memoryPool();
QStringRef newStringRef(const QString &string);
@@ -124,8 +124,7 @@ private:
QHash<int, QQmlCustomParser*> customParsers;
// index in first hash is component index, vector inside contains object indices of objects with id property
- QHash<int, QVector<quint32>> m_namedObjectsPerComponent;
- QVector<quint32> m_namedObjectsInRootScope;
+ QVector<quint32> m_componentRoots;
};
struct QQmlCompilePass
@@ -272,17 +271,14 @@ protected:
const int indexOfRootObject;
// indices of the objects that are actually Component {}
- QVector<int> componentRoots;
+ QVector<quint32> componentRoots;
int _componentIndex;
QHash<int, int> _idToObjectIndex;
- QVector<quint32> *_namedObjectsInScope;
QList<int> _objectsWithAliases;
QHash<int, QQmlCompiledData::TypeReference*> *resolvedTypes;
QQmlPropertyCacheVector propertyCaches;
- QVector<quint32> *namedObjectsInRootScope;
- QHash<int, QVector<quint32>> *namedObjectsPerComponent;
};
class QQmlPropertyValidator : public QQmlCompilePass
@@ -325,7 +321,7 @@ public:
bool generateCodeForComponents();
private:
- bool compileComponent(int componentRoot, const QVector<quint32> &namedObjects);
+ bool compileComponent(int componentRoot);
bool compileJavaScriptCodeInObjectsRecursively(int objectIndex, int scopeObjectIndex);
const QHash<int, QQmlCompiledData::TypeReference*> &resolvedTypes;