diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-05-29 09:33:26 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2016-05-31 06:55:02 +0000 |
commit | 3241573e1a72f2829d1339cd5bbe62f30d93c37f (patch) | |
tree | 1d97a226af23f8a92591a4cbdb97a2dfc7b941e2 /src/qml | |
parent | 7dc5cd942eb5c55a26d539eedff48b2d6c8e0fc3 (diff) |
Move property caches from QQmlCompiledData to QV4::CompiledData::CompilationUnit
This makes particularly sense as the binding property data per object that
allows us to avoid a by-name property lookup when instantiating types is also
stored there.
Change-Id: I4d9275c1d8fde252df83eb11a9dfea71e5e9583a
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/compiler/qqmltypecompiler.cpp | 13 | ||||
-rw-r--r-- | src/qml/compiler/qqmltypecompiler_p.h | 1 | ||||
-rw-r--r-- | src/qml/compiler/qv4compileddata.cpp | 6 | ||||
-rw-r--r-- | src/qml/compiler/qv4compileddata_p.h | 9 | ||||
-rw-r--r-- | src/qml/qml/qqmlcompileddata.cpp | 10 | ||||
-rw-r--r-- | src/qml/qml/qqmlcompiler_p.h | 8 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 10 | ||||
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 4 |
9 files changed, 33 insertions, 30 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 1f9e0e2752..0d3fc4f10b 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -137,8 +137,6 @@ bool QQmlTypeCompiler::compile() customParsers.insert(it.key(), customParser); } - compiledData->propertyCaches.reserve(document->objects.count()); - { QQmlPropertyCacheCreator propertyCacheBuilder(this); if (!propertyCacheBuilder.buildMetaObjects()) @@ -242,9 +240,10 @@ bool QQmlTypeCompiler::compile() document->javaScriptCompilationUnit->data = qmlUnit; compiledData->compilationUnit = document->javaScriptCompilationUnit; + compiledData->compilationUnit->propertyCaches = m_propertyCaches; // Add to type registry of composites - if (compiledData->isCompositeType()) + if (compiledData->compilationUnit->isCompositeType()) engine->registerInternalCompositeType(compiledData); else { const QV4::CompiledData::Object *obj = qmlUnit->objectAt(qmlUnit->indexOfRootObject); @@ -289,7 +288,7 @@ bool QQmlTypeCompiler::compile() compiledData->totalParserStatusCount = parserStatusCount; compiledData->totalObjectCount = objectCount; - Q_ASSERT(compiledData->propertyCaches.count() == static_cast<int>(compiledData->compilationUnit->data->nObjects)); + Q_ASSERT(compiledData->compilationUnit->propertyCaches.count() == static_cast<int>(compiledData->compilationUnit->data->nObjects)); return errors.isEmpty(); } @@ -343,13 +342,13 @@ int QQmlTypeCompiler::rootObjectIndex() const void QQmlTypeCompiler::setPropertyCaches(const QQmlPropertyCacheVector &caches) { - compiledData->propertyCaches = caches; + m_propertyCaches = caches; Q_ASSERT(caches.count() >= document->indexOfRootObject); } const QQmlPropertyCacheVector &QQmlTypeCompiler::propertyCaches() const { - return compiledData->propertyCaches; + return m_propertyCaches; } QQmlJS::MemoryPool *QQmlTypeCompiler::memoryPool() @@ -1334,7 +1333,7 @@ void QQmlComponentAndAliasResolver::findAndRegisterImplicitComponents(const QmlI if (targetType->metaObject() == &QQmlComponent::staticMetaObject) continue; } else if (tr->component) { - if (tr->component->rootPropertyCache()->firstCppMetaObject() == &QQmlComponent::staticMetaObject) + if (tr->component->compilationUnit->rootPropertyCache()->firstCppMetaObject() == &QQmlComponent::staticMetaObject) continue; } diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h index 64d2e6c925..d84753347a 100644 --- a/src/qml/compiler/qqmltypecompiler_p.h +++ b/src/qml/compiler/qqmltypecompiler_p.h @@ -123,6 +123,7 @@ private: // index in first hash is component index, vector inside contains object indices of objects with id property QVector<quint32> m_componentRoots; + QQmlPropertyCacheVector m_propertyCaches; }; struct QQmlCompilePass diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index e9955ffb04..3472c955c8 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -165,6 +165,12 @@ void CompilationUnit::unlink() { if (engine) engine->compilationUnits.erase(engine->compilationUnits.find(this)); + + for (int ii = 0; ii < propertyCaches.count(); ++ii) + if (propertyCaches.at(ii).data()) + propertyCaches.at(ii)->release(); + propertyCaches.clear(); + engine = 0; free(runtimeStrings); runtimeStrings = 0; diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index a9927f33a9..bc75dd0298 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -61,12 +61,17 @@ #include <private/qqmlrefcount_p.h> #include <private/qqmlnullablevalue_p.h> #include <private/qv4identifier_p.h> +#include <private/qflagpointer_p.h> QT_BEGIN_NAMESPACE class QQmlPropertyCache; class QQmlPropertyData; +// The vector is indexed by QV4::CompiledData::Object index and the flag +// indicates whether instantiation of the object requires a VME meta-object. +typedef QVector<QFlagPointer<QQmlPropertyCache>> QQmlPropertyCacheVector; + namespace QmlIR { struct Document; } @@ -661,6 +666,10 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount QVector<QV4::Function *> runtimeFunctions; mutable QQmlNullableValue<QUrl> m_url; + QQmlPropertyCacheVector propertyCaches; + QQmlPropertyCache *rootPropertyCache() const { return propertyCaches.at(data->indexOfRootObject).data(); } + bool isCompositeType() const { return propertyCaches.at(data->indexOfRootObject).flag(); } + // index is object index. This allows fast access to the // property data when initializing bindings, avoiding expensive // lookups by string (property name). diff --git a/src/qml/qml/qqmlcompileddata.cpp b/src/qml/qml/qqmlcompileddata.cpp index 1037b5da51..0305f3605f 100644 --- a/src/qml/qml/qqmlcompileddata.cpp +++ b/src/qml/qml/qqmlcompileddata.cpp @@ -91,10 +91,6 @@ QQmlCompiledData::~QQmlCompiledData() if (importCache) importCache->release(); - - for (int ii = 0; ii < propertyCaches.count(); ++ii) - if (propertyCaches.at(ii).data()) - propertyCaches.at(ii)->release(); } void QQmlCompiledData::clear() @@ -109,7 +105,7 @@ QQmlPropertyCache *QQmlCompiledData::TypeReference::propertyCache() const if (type) return typePropertyCache; else - return component->rootPropertyCache(); + return component->compilationUnit->rootPropertyCache(); } /*! @@ -124,7 +120,7 @@ QQmlPropertyCache *QQmlCompiledData::TypeReference::createPropertyCache(QQmlEngi typePropertyCache->addref(); return typePropertyCache; } else { - return component->rootPropertyCache(); + return component->compilationUnit->rootPropertyCache(); } } @@ -146,7 +142,7 @@ void QQmlCompiledData::TypeReference::doDynamicTypeCheck() else if (type) mo = type->metaObject(); else if (component) - mo = component->rootPropertyCache()->firstCppMetaObject(); + mo = component->compilationUnit->rootPropertyCache()->firstCppMetaObject(); isFullyDynamicType = qtTypeInherits<QQmlPropertyMap>(mo); } diff --git a/src/qml/qml/qqmlcompiler_p.h b/src/qml/qml/qqmlcompiler_p.h index 60900f0185..55247abae9 100644 --- a/src/qml/qml/qqmlcompiler_p.h +++ b/src/qml/qml/qqmlcompiler_p.h @@ -80,10 +80,6 @@ class QQmlComponent; class QQmlContext; class QQmlContextData; -// The vector is indexed by QV4::CompiledData::Object index and the flag -// indicates whether instantiation of the object requires a VME meta-object. -typedef QVector<QFlagPointer<QQmlPropertyCache>> QQmlPropertyCacheVector; - // ### Merge with QV4::CompiledData::CompilationUnit class Q_AUTOTEST_EXPORT QQmlCompiledData : public QQmlRefCount, public QQmlCleanup { @@ -126,8 +122,6 @@ public: // map from name index QHash<int, TypeReference*> resolvedTypes; - QQmlPropertyCache *rootPropertyCache() const { return propertyCaches.at(compilationUnit->data->indexOfRootObject).data(); } - QQmlPropertyCacheVector propertyCaches; QList<QQmlScriptData *> scripts; QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit; @@ -136,8 +130,6 @@ public: int totalParserStatusCount; // Number of instantiated types that are QQmlParserStatus subclasses int totalObjectCount; // Number of objects explicitly instantiated - bool isCompositeType() const { return propertyCaches.at(compilationUnit->data->indexOfRootObject).flag(); } - bool isInitialized() const { return hasEngine(); } void initialize(QQmlEngine *); diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 2baca619cc..fd1795499e 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -2227,7 +2227,7 @@ QQmlMetaObject QQmlEnginePrivate::rawMetaObjectForType(int t) const Locker locker(this); QHash<int, QQmlCompiledData *>::ConstIterator iter = m_compositeTypes.constFind(t); if (iter != m_compositeTypes.cend()) { - return QQmlMetaObject((*iter)->rootPropertyCache()); + return QQmlMetaObject((*iter)->compilationUnit->rootPropertyCache()); } else { QQmlType *type = QQmlMetaType::qmlType(t); return QQmlMetaObject(type?type->baseMetaObject():0); @@ -2239,7 +2239,7 @@ QQmlMetaObject QQmlEnginePrivate::metaObjectForType(int t) const Locker locker(this); QHash<int, QQmlCompiledData *>::ConstIterator iter = m_compositeTypes.constFind(t); if (iter != m_compositeTypes.cend()) { - return QQmlMetaObject((*iter)->rootPropertyCache()); + return QQmlMetaObject((*iter)->compilationUnit->rootPropertyCache()); } else { QQmlType *type = QQmlMetaType::qmlType(t); return QQmlMetaObject(type?type->metaObject():0); @@ -2251,7 +2251,7 @@ QQmlPropertyCache *QQmlEnginePrivate::propertyCacheForType(int t) Locker locker(this); QHash<int, QQmlCompiledData*>::ConstIterator iter = m_compositeTypes.constFind(t); if (iter != m_compositeTypes.cend()) { - return (*iter)->rootPropertyCache(); + return (*iter)->compilationUnit->rootPropertyCache(); } else { QQmlType *type = QQmlMetaType::qmlType(t); locker.unlock(); @@ -2264,7 +2264,7 @@ QQmlPropertyCache *QQmlEnginePrivate::rawPropertyCacheForType(int t) Locker locker(this); QHash<int, QQmlCompiledData*>::ConstIterator iter = m_compositeTypes.constFind(t); if (iter != m_compositeTypes.cend()) { - return (*iter)->rootPropertyCache(); + return (*iter)->compilationUnit->rootPropertyCache(); } else { QQmlType *type = QQmlMetaType::qmlType(t); locker.unlock(); @@ -2274,7 +2274,7 @@ QQmlPropertyCache *QQmlEnginePrivate::rawPropertyCacheForType(int t) void QQmlEnginePrivate::registerInternalCompositeType(QQmlCompiledData *data) { - QByteArray name = data->rootPropertyCache()->className(); + QByteArray name = data->compilationUnit->rootPropertyCache()->className(); QByteArray ptr = name + '*'; QByteArray lst = "QQmlListProperty<" + name + '>'; diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index f3f4c41775..1b3997baae 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -494,7 +494,7 @@ QQmlType *QQmlType::resolveCompositeBaseType(QQmlEnginePrivate *engine) const if (!td || !td->isComplete()) return 0; QQmlCompiledData *cd = td->compiledData(); - const QMetaObject *mo = cd->rootPropertyCache()->firstCppMetaObject(); + const QMetaObject *mo = cd->compilationUnit->rootPropertyCache()->firstCppMetaObject(); return QQmlMetaType::qmlType(mo); } diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 82ec454b68..798c8c8c5d 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -73,7 +73,7 @@ QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, QQmlCompile : phase(Startup) , compiledData(compiledData) , resolvedTypes(compiledData->resolvedTypes) - , propertyCaches(compiledData->propertyCaches) + , propertyCaches(compiledData->compilationUnit->propertyCaches) , activeVMEDataForRootContext(activeVMEDataForRootContext) { init(parentContext); @@ -97,7 +97,7 @@ QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, QQmlCompile : phase(Startup) , compiledData(compiledData) , resolvedTypes(compiledData->resolvedTypes) - , propertyCaches(compiledData->propertyCaches) + , propertyCaches(compiledData->compilationUnit->propertyCaches) , activeVMEDataForRootContext(0) { init(parentContext); |