aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp109
-rw-r--r--src/qml/compiler/qqmltypecompiler_p.h23
-rw-r--r--src/qml/qml/qqmlcompiler_p.h4
-rw-r--r--src/qml/qml/qqmlobjectcreator_p.h4
4 files changed, 86 insertions, 54 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index 50bb5ef5a1..0c4ebcdf01 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -99,33 +99,11 @@ bool QQmlTypeCompiler::compile()
compiledData->datas.reserve(objectCount);
compiledData->propertyCaches.reserve(objectCount);
- QQmlPropertyCacheCreator propertyCacheBuilder(this);
-
- for (int i = 0; i < objectCount; ++i) {
- const QtQml::QmlObject *obj = parsedQML->objects.at(i);
-
- QByteArray vmeMetaObjectData;
- QQmlPropertyCache *propertyCache = 0;
-
- // If the object has no type, then it's probably a nested object definition as part
- // of a group property.
- const bool objectHasType = !propertyCacheBuilder.stringAt(obj->inheritedTypeNameIndex).isEmpty();
- if (objectHasType) {
- if (!propertyCacheBuilder.create(obj, &propertyCache, &vmeMetaObjectData)) {
- errors << propertyCacheBuilder.errors;
- return false;
- }
- }
-
- compiledData->datas << vmeMetaObjectData;
- if (propertyCache)
- propertyCache->addref();
- compiledData->propertyCaches << propertyCache;
-
- if (i == parsedQML->indexOfRootObject) {
- Q_ASSERT(propertyCache);
- compiledData->rootPropertyCache = propertyCache;
- propertyCache->addref();
+ {
+ QQmlPropertyCacheCreator propertyCacheBuilder(this);
+ if (!propertyCacheBuilder.buildMetaObjects()) {
+ errors << propertyCacheBuilder.errors;
+ return false;
}
}
@@ -263,12 +241,26 @@ int QQmlTypeCompiler::rootObjectIndex() const
return parsedQML->indexOfRootObject;
}
-const QList<QQmlPropertyCache *> &QQmlTypeCompiler::propertyCaches() const
+void QQmlTypeCompiler::setPropertyCaches(const QVector<QQmlPropertyCache *> &caches)
+{
+ Q_ASSERT(compiledData->propertyCaches.isEmpty());
+ compiledData->propertyCaches = caches;
+ Q_ASSERT(caches.count() >= parsedQML->indexOfRootObject);
+ compiledData->rootPropertyCache = caches.at(parsedQML->indexOfRootObject);
+}
+
+const QVector<QQmlPropertyCache *> &QQmlTypeCompiler::propertyCaches() const
{
return compiledData->propertyCaches;
}
-QList<QByteArray> *QQmlTypeCompiler::vmeMetaObjects() const
+void QQmlTypeCompiler::setVMEMetaObjects(const QVector<QByteArray> &metaObjects)
+{
+ Q_ASSERT(compiledData->datas.isEmpty());
+ compiledData->datas = metaObjects;
+}
+
+QVector<QByteArray> *QQmlTypeCompiler::vmeMetaObjects() const
{
return &compiledData->datas;
}
@@ -312,31 +304,62 @@ static QAtomicInt classIndexCounter(0);
QQmlPropertyCacheCreator::QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler)
: QQmlCompilePass(typeCompiler)
, enginePrivate(typeCompiler->enginePrivate())
+ , qmlObjects(*typeCompiler->qmlObjects())
, imports(typeCompiler->imports())
, resolvedTypes(typeCompiler->resolvedTypes())
{
}
-bool QQmlPropertyCacheCreator::create(const QtQml::QmlObject *obj, QQmlPropertyCache **resultCache, QByteArray *vmeMetaObjectData)
+QQmlPropertyCacheCreator::~QQmlPropertyCacheCreator()
{
- Q_ASSERT(!stringAt(obj->inheritedTypeNameIndex).isEmpty());
-
- QQmlCompiledData::TypeReference typeRef = resolvedTypes->value(obj->inheritedTypeNameIndex);
- QQmlPropertyCache *baseTypeCache = typeRef.createPropertyCache(QQmlEnginePrivate::get(enginePrivate));
- Q_ASSERT(baseTypeCache);
- if (obj->properties->count == 0 && obj->qmlSignals->count == 0 && obj->functions->count == 0) {
- *resultCache = baseTypeCache;
- vmeMetaObjectData->clear();
- return true;
+ for (int i = 0; i < propertyCaches.count(); ++i)
+ if (QQmlPropertyCache *cache = propertyCaches.at(i))
+ cache->release();
+ propertyCaches.clear();
+}
+
+bool QQmlPropertyCacheCreator::buildMetaObjects()
+{
+ propertyCaches.resize(qmlObjects.count());
+ vmeMetaObjects.resize(qmlObjects.count());
+
+ for (int i = 0; i < qmlObjects.count(); ++i) {
+ const QtQml::QmlObject *obj = qmlObjects.at(i);
+
+ // If the object has no type, then it's probably a nested object definition as part
+ // of a group property.
+ const bool objectHasType = !stringAt(obj->inheritedTypeNameIndex).isEmpty();
+ if (objectHasType) {
+ QQmlCompiledData::TypeReference typeRef = resolvedTypes->value(obj->inheritedTypeNameIndex);
+ QQmlPropertyCache *baseTypeCache = typeRef.createPropertyCache(QQmlEnginePrivate::get(enginePrivate));
+ Q_ASSERT(baseTypeCache);
+
+ bool needVMEMetaObject = obj->properties->count != 0 || obj->qmlSignals->count != 0 || obj->functions->count != 0;
+ if (needVMEMetaObject) {
+ if (!createMetaObject(i, obj, baseTypeCache))
+ return false;
+ } else {
+ propertyCaches[i] = baseTypeCache;
+ baseTypeCache->addref();
+ }
+ }
}
+ compiler->setVMEMetaObjects(vmeMetaObjects);
+ compiler->setPropertyCaches(propertyCaches);
+ propertyCaches.clear();
+
+ return true;
+}
+
+bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QtQml::QmlObject *obj, QQmlPropertyCache *baseTypeCache)
+{
QQmlPropertyCache *cache = baseTypeCache->copyAndReserve(QQmlEnginePrivate::get(enginePrivate),
obj->properties->count,
obj->functions->count + obj->properties->count + obj->qmlSignals->count,
obj->qmlSignals->count + obj->properties->count);
- *resultCache = cache;
-
- vmeMetaObjectData->clear();
+ propertyCaches[objectIndex] = cache;
+ cache->addref();
struct TypeData {
QV4::CompiledData::Property::Type dtype;
@@ -406,7 +429,7 @@ bool QQmlPropertyCacheCreator::create(const QtQml::QmlObject *obj, QQmlPropertyC
typedef QQmlVMEMetaData VMD;
- QByteArray &dynamicData = *vmeMetaObjectData = QByteArray(sizeof(QQmlVMEMetaData)
+ QByteArray &dynamicData = vmeMetaObjects[objectIndex] = QByteArray(sizeof(QQmlVMEMetaData)
+ obj->properties->count * sizeof(VMD::PropertyData)
+ obj->functions->count * sizeof(VMD::MethodData)
+ aliasCount * sizeof(VMD::AliasData), 0);
diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h
index 9f055f4376..7f7adf1c86 100644
--- a/src/qml/compiler/qqmltypecompiler_p.h
+++ b/src/qml/compiler/qqmltypecompiler_p.h
@@ -84,8 +84,10 @@ struct QQmlTypeCompiler
QHash<int, QQmlCompiledData::TypeReference> *resolvedTypes();
QList<QtQml::QmlObject*> *qmlObjects();
int rootObjectIndex() const;
- const QList<QQmlPropertyCache *> &propertyCaches() const;
- QList<QByteArray> *vmeMetaObjects() const;
+ void setPropertyCaches(const QVector<QQmlPropertyCache *> &caches);
+ const QVector<QQmlPropertyCache *> &propertyCaches() const;
+ void setVMEMetaObjects(const QVector<QByteArray> &metaObjects);
+ QVector<QByteArray> *vmeMetaObjects() const;
QHash<int, int> *objectIndexToIdForRoot();
QHash<int, QHash<int, int> > *objectIndexToIdPerComponent();
QHash<int, QByteArray> *customParserData();
@@ -101,6 +103,8 @@ private:
struct QQmlCompilePass
{
+ virtual ~QQmlCompilePass() {}
+
QQmlCompilePass(QQmlTypeCompiler *typeCompiler);
QList<QQmlError> errors;
@@ -117,13 +121,18 @@ class QQmlPropertyCacheCreator : public QQmlCompilePass
Q_DECLARE_TR_FUNCTIONS(QQmlPropertyCacheCreator)
public:
QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler);
+ ~QQmlPropertyCacheCreator();
- bool create(const QtQml::QmlObject *obj, QQmlPropertyCache **cache, QByteArray *vmeMetaObjectData);
-
+ bool buildMetaObjects();
protected:
+ bool createMetaObject(int objectIndex, const QtQml::QmlObject *obj, QQmlPropertyCache *baseTypeCache);
+
QQmlEnginePrivate *enginePrivate;
+ const QList<QtQml::QmlObject*> &qmlObjects;
const QQmlImports *imports;
QHash<int, QQmlCompiledData::TypeReference> *resolvedTypes;
+ QVector<QByteArray> vmeMetaObjects;
+ QVector<QQmlPropertyCache*> propertyCaches;
};
class QQmlComponentAndAliasResolver : public QQmlCompilePass
@@ -157,8 +166,8 @@ protected:
QList<int> _objectsWithAliases;
QHash<int, QQmlCompiledData::TypeReference> *resolvedTypes;
- const QList<QQmlPropertyCache *> propertyCaches;
- QList<QByteArray> *vmeMetaObjectData;
+ const QVector<QQmlPropertyCache *> propertyCaches;
+ QVector<QByteArray> *vmeMetaObjectData;
QHash<int, int> *objectIndexToIdForRoot;
QHash<int, QHash<int, int> > *objectIndexToIdPerComponent;
};
@@ -178,7 +187,7 @@ private:
const QV4::CompiledData::QmlUnit *qmlUnit;
const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes;
- const QList<QQmlPropertyCache *> &propertyCaches;
+ const QVector<QQmlPropertyCache *> &propertyCaches;
const QHash<int, QHash<int, int> > objectIndexToIdPerComponent;
QHash<int, QByteArray> *customParserData;
};
diff --git a/src/qml/qml/qqmlcompiler_p.h b/src/qml/qml/qqmlcompiler_p.h
index d410d396e3..c94cee16cf 100644
--- a/src/qml/qml/qqmlcompiler_p.h
+++ b/src/qml/qml/qqmlcompiler_p.h
@@ -144,9 +144,9 @@ public:
QQmlPropertyCache *rootPropertyCache;
QList<QString> primitives;
- QList<QByteArray> datas;
+ QVector<QByteArray> datas;
QByteArray bytecode;
- QList<QQmlPropertyCache *> propertyCaches;
+ QVector<QQmlPropertyCache *> propertyCaches;
QList<QVector<QQmlContextData::ObjectIdMapping> > contextCaches;
QList<QQmlScriptData *> scripts;
QList<QUrl> urls;
diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h
index 3c180c65f7..a198396467 100644
--- a/src/qml/qml/qqmlobjectcreator_p.h
+++ b/src/qml/qml/qqmlobjectcreator_p.h
@@ -87,8 +87,8 @@ private:
QQmlContextData *parentContext;
QQmlContextData *context;
const QHash<int, QQmlCompiledData::TypeReference> resolvedTypes;
- const QList<QQmlPropertyCache *> propertyCaches;
- const QList<QByteArray> vmeMetaObjectData;
+ const QVector<QQmlPropertyCache *> propertyCaches;
+ const QVector<QByteArray> vmeMetaObjectData;
QHash<int, int> objectIndexToId;
QLinkedList<QVector<QQmlAbstractBinding*> > allCreatedBindings;
QLinkedList<QVector<QQmlParserStatus*> > allParserStatusCallbacks;