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>
This commit is contained in:
Simon Hausmann 2016-05-26 11:17:31 +02:00
parent 18f9655162
commit 777aac3005
3 changed files with 27 additions and 38 deletions

View File

@ -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 { const T &at(int index) const {
Q_ASSERT(index >= 0 && index < count); Q_ASSERT(index >= 0 && index < count);
return data[index]; return data[index];

View File

@ -346,16 +346,6 @@ const QQmlPropertyCacheVector &QQmlTypeCompiler::propertyCaches() const
return compiledData->propertyCaches; return compiledData->propertyCaches;
} }
QVector<quint32> *QQmlTypeCompiler::namedObjectsInRootScope()
{
return &m_namedObjectsInRootScope;
}
QHash<int, QVector<quint32>> *QQmlTypeCompiler::namedObjectsPerComponent()
{
return &m_namedObjectsPerComponent;
}
QHash<int, QBitArray> *QQmlTypeCompiler::customParserBindings() QHash<int, QBitArray> *QQmlTypeCompiler::customParserBindings()
{ {
return &compiledData->customParserBindings; return &compiledData->customParserBindings;
@ -1324,11 +1314,8 @@ QQmlComponentAndAliasResolver::QQmlComponentAndAliasResolver(QQmlTypeCompiler *t
, qmlObjects(typeCompiler->qmlObjects()) , qmlObjects(typeCompiler->qmlObjects())
, indexOfRootObject(typeCompiler->rootObjectIndex()) , indexOfRootObject(typeCompiler->rootObjectIndex())
, _componentIndex(-1) , _componentIndex(-1)
, _namedObjectsInScope(0)
, resolvedTypes(typeCompiler->resolvedTypes()) , resolvedTypes(typeCompiler->resolvedTypes())
, propertyCaches(typeCompiler->propertyCaches()) , propertyCaches(typeCompiler->propertyCaches())
, namedObjectsInRootScope(typeCompiler->namedObjectsInRootScope())
, namedObjectsPerComponent(typeCompiler->namedObjectsPerComponent())
{ {
} }
@ -1475,8 +1462,6 @@ bool QQmlComponentAndAliasResolver::resolve()
_componentIndex = i; _componentIndex = i;
_idToObjectIndex.clear(); _idToObjectIndex.clear();
_namedObjectsInScope = &(*namedObjectsPerComponent)[componentRoots.at(i)];
_objectsWithAliases.clear(); _objectsWithAliases.clear();
if (!collectIdsAndAliases(rootBinding->value.objectIndex)) if (!collectIdsAndAliases(rootBinding->value.objectIndex))
@ -1485,13 +1470,12 @@ bool QQmlComponentAndAliasResolver::resolve()
if (!resolveAliases()) if (!resolveAliases())
return false; return false;
component->namedObjectsInComponent.allocate(pool, *_namedObjectsInScope); component->namedObjectsInComponent.allocate(pool, _idToObjectIndex);
} }
// Collect ids and aliases for root // Collect ids and aliases for root
_componentIndex = -1; _componentIndex = -1;
_idToObjectIndex.clear(); _idToObjectIndex.clear();
_namedObjectsInScope = namedObjectsInRootScope;
_objectsWithAliases.clear(); _objectsWithAliases.clear();
collectIdsAndAliases(indexOfRootObject); collectIdsAndAliases(indexOfRootObject);
@ -1499,11 +1483,12 @@ bool QQmlComponentAndAliasResolver::resolve()
resolveAliases(); resolveAliases();
QmlIR::Object *rootComponent = qmlObjects->at(indexOfRootObject); 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 // Implicit component insertion may have added objects and thus we also need
// to extend the symmetric propertyCaches. // to extend the symmetric propertyCaches.
compiler->setPropertyCaches(propertyCaches); compiler->setPropertyCaches(propertyCaches);
compiler->setComponentRoots(componentRoots);
return true; return true;
} }
@ -1517,9 +1502,8 @@ bool QQmlComponentAndAliasResolver::collectIdsAndAliases(int objectIndex)
recordError(obj->locationOfIdProperty, tr("id is not unique")); recordError(obj->locationOfIdProperty, tr("id is not unique"));
return false; return false;
} }
obj->id = _idToObjectIndex.count();
_idToObjectIndex.insert(obj->idNameIndex, objectIndex); _idToObjectIndex.insert(obj->idNameIndex, objectIndex);
obj->id = _namedObjectsInScope->count();
_namedObjectsInScope->append(objectIndex);
} }
if (obj->aliasCount() > 0) if (obj->aliasCount() > 0)
@ -2383,17 +2367,16 @@ QQmlJSCodeGenerator::QQmlJSCodeGenerator(QQmlTypeCompiler *typeCompiler, QmlIR::
bool QQmlJSCodeGenerator::generateCodeForComponents() bool QQmlJSCodeGenerator::generateCodeForComponents()
{ {
const QHash<int, QVector<quint32>> &namedObjectsPerComponent = *compiler->namedObjectsPerComponent(); const QVector<quint32> &componentRoots = compiler->componentRoots();
for (QHash<int, QVector<quint32>>::ConstIterator component = namedObjectsPerComponent.constBegin(), end = namedObjectsPerComponent.constEnd(); for (int i = 0; i < componentRoots.count(); ++i) {
component != end; ++component) { if (!compileComponent(componentRoots.at(i)))
if (!compileComponent(component.key(), component.value()))
return false; 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); const QmlIR::Object *obj = qmlObjects.at(contextObject);
if (obj->flags & QV4::CompiledData::Object::IsComponent) { if (obj->flags & QV4::CompiledData::Object::IsComponent) {
@ -2404,9 +2387,9 @@ bool QQmlJSCodeGenerator::compileComponent(int contextObject, const QVector<quin
} }
QmlIR::JSCodeGen::ObjectIdMapping idMapping; QmlIR::JSCodeGen::ObjectIdMapping idMapping;
idMapping.reserve(namedObjects.count()); idMapping.reserve(obj->namedObjectsInComponent.count);
for (int i = 0; i < namedObjects.count(); ++i) { for (int i = 0; i < obj->namedObjectsInComponent.count; ++i) {
const int objectIndex = namedObjects.at(i); const int objectIndex = obj->namedObjectsInComponent.at(i);
QmlIR::JSCodeGen::IdMapping m; QmlIR::JSCodeGen::IdMapping m;
const QmlIR::Object *obj = qmlObjects.at(objectIndex); const QmlIR::Object *obj = qmlObjects.at(objectIndex);
m.name = stringAt(obj->idNameIndex); m.name = stringAt(obj->idNameIndex);

View File

@ -101,8 +101,8 @@ public:
int rootObjectIndex() const; int rootObjectIndex() const;
void setPropertyCaches(const QQmlPropertyCacheVector &caches); void setPropertyCaches(const QQmlPropertyCacheVector &caches);
const QQmlPropertyCacheVector &propertyCaches() const; const QQmlPropertyCacheVector &propertyCaches() const;
QVector<quint32> *namedObjectsInRootScope(); void setComponentRoots(const QVector<quint32> &roots) { m_componentRoots = roots; }
QHash<int, QVector<quint32> > *namedObjectsPerComponent(); const QVector<quint32> &componentRoots() const { return m_componentRoots; }
QHash<int, QBitArray> *customParserBindings(); QHash<int, QBitArray> *customParserBindings();
QQmlJS::MemoryPool *memoryPool(); QQmlJS::MemoryPool *memoryPool();
QStringRef newStringRef(const QString &string); QStringRef newStringRef(const QString &string);
@ -124,8 +124,7 @@ private:
QHash<int, QQmlCustomParser*> customParsers; QHash<int, QQmlCustomParser*> customParsers;
// index in first hash is component index, vector inside contains object indices of objects with id property // 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_componentRoots;
QVector<quint32> m_namedObjectsInRootScope;
}; };
struct QQmlCompilePass struct QQmlCompilePass
@ -272,17 +271,14 @@ protected:
const int indexOfRootObject; const int indexOfRootObject;
// indices of the objects that are actually Component {} // indices of the objects that are actually Component {}
QVector<int> componentRoots; QVector<quint32> componentRoots;
int _componentIndex; int _componentIndex;
QHash<int, int> _idToObjectIndex; QHash<int, int> _idToObjectIndex;
QVector<quint32> *_namedObjectsInScope;
QList<int> _objectsWithAliases; QList<int> _objectsWithAliases;
QHash<int, QQmlCompiledData::TypeReference*> *resolvedTypes; QHash<int, QQmlCompiledData::TypeReference*> *resolvedTypes;
QQmlPropertyCacheVector propertyCaches; QQmlPropertyCacheVector propertyCaches;
QVector<quint32> *namedObjectsInRootScope;
QHash<int, QVector<quint32>> *namedObjectsPerComponent;
}; };
class QQmlPropertyValidator : public QQmlCompilePass class QQmlPropertyValidator : public QQmlCompilePass
@ -325,7 +321,7 @@ public:
bool generateCodeForComponents(); bool generateCodeForComponents();
private: private:
bool compileComponent(int componentRoot, const QVector<quint32> &namedObjects); bool compileComponent(int componentRoot);
bool compileJavaScriptCodeInObjectsRecursively(int objectIndex, int scopeObjectIndex); bool compileJavaScriptCodeInObjectsRecursively(int objectIndex, int scopeObjectIndex);
const QHash<int, QQmlCompiledData::TypeReference*> &resolvedTypes; const QHash<int, QQmlCompiledData::TypeReference*> &resolvedTypes;