Moved the import cache from QQmlCompiledData to CompilationUnit

Change-Id: I77892919678cb01ba1e697a44122760679a72045
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Simon Hausmann 2016-05-29 18:42:28 +02:00 committed by Simon Hausmann
parent 3241573e1a
commit 77773997d0
7 changed files with 20 additions and 14 deletions

View File

@ -65,16 +65,16 @@ QQmlTypeCompiler::QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlCompiledData *
bool QQmlTypeCompiler::compile()
{
compiledData->importCache = new QQmlTypeNameCache;
importCache = new QQmlTypeNameCache;
foreach (const QString &ns, typeData->namespaces())
compiledData->importCache->add(ns);
importCache->add(ns);
// Add any Composite Singletons that were used to the import cache
foreach (const QQmlTypeData::TypeReference &singleton, typeData->compositeSingletons())
compiledData->importCache->add(singleton.type->qmlTypeName(), singleton.type->sourceUrl(), singleton.prefix);
importCache->add(singleton.type->qmlTypeName(), singleton.type->sourceUrl(), singleton.prefix);
typeData->imports().populateCache(compiledData->importCache);
typeData->imports().populateCache(importCache.data());
const QHash<int, QQmlTypeData::TypeReference> &resolvedTypes = typeData->resolvedTypeRefs();
for (QHash<int, QQmlTypeData::TypeReference>::ConstIterator resolvedType = resolvedTypes.constBegin(), end = resolvedTypes.constEnd();
@ -185,7 +185,7 @@ bool QQmlTypeCompiler::compile()
qualifier = qualifier.mid(lastDotIndex+1);
}
compiledData->importCache->add(qualifier.toString(), scriptIndex, enclosingNamespace);
importCache->add(qualifier.toString(), scriptIndex, enclosingNamespace);
QQmlScriptData *scriptData = script.script->scriptData();
scriptData->addref();
compiledData->scripts << scriptData;
@ -215,7 +215,7 @@ bool QQmlTypeCompiler::compile()
sss.scan();
}
QmlIR::JSCodeGen v4CodeGenerator(typeData->finalUrlString(), document->code, &document->jsModule, &document->jsParserEngine, document->program, compiledData->importCache, &document->jsGenerator.stringTable);
QmlIR::JSCodeGen v4CodeGenerator(typeData->finalUrlString(), document->code, &document->jsModule, &document->jsParserEngine, document->program, importCache, &document->jsGenerator.stringTable);
QQmlJSCodeGenerator jsCodeGen(this, &v4CodeGenerator);
if (!jsCodeGen.generateCodeForComponents())
return false;
@ -241,6 +241,7 @@ bool QQmlTypeCompiler::compile()
compiledData->compilationUnit = document->javaScriptCompilationUnit;
compiledData->compilationUnit->propertyCaches = m_propertyCaches;
compiledData->compilationUnit->importCache = importCache;
// Add to type registry of composites
if (compiledData->compilationUnit->isCompositeType())

View File

@ -117,6 +117,7 @@ private:
QQmlEnginePrivate *engine;
QQmlCompiledData *compiledData;
QQmlTypeData *typeData;
QQmlRefPointer<QQmlTypeNameCache> importCache;
QmlIR::Document *document;
// index is string index of type name (use obj->inheritedTypeNameIndex)
QHash<int, QQmlCustomParser*> customParsers;

View File

@ -171,6 +171,8 @@ void CompilationUnit::unlink()
propertyCaches.at(ii)->release();
propertyCaches.clear();
importCache = nullptr;
engine = 0;
free(runtimeStrings);
runtimeStrings = 0;

View File

@ -62,11 +62,15 @@
#include <private/qqmlnullablevalue_p.h>
#include <private/qv4identifier_p.h>
#include <private/qflagpointer_p.h>
#ifndef V4_BOOTSTRAP
#include <private/qqmltypenamecache_p.h>
#endif
QT_BEGIN_NAMESPACE
class QQmlPropertyCache;
class QQmlPropertyData;
class QQmlTypeNameCache;
// The vector is indexed by QV4::CompiledData::Object index and the flag
// indicates whether instantiation of the object requires a VME meta-object.
@ -666,10 +670,13 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount
QVector<QV4::Function *> runtimeFunctions;
mutable QQmlNullableValue<QUrl> m_url;
// QML specific fields
QQmlPropertyCacheVector propertyCaches;
QQmlPropertyCache *rootPropertyCache() const { return propertyCaches.at(data->indexOfRootObject).data(); }
bool isCompositeType() const { return propertyCaches.at(data->indexOfRootObject).flag(); }
QQmlRefPointer<QQmlTypeNameCache> importCache;
// index is object index. This allows fast access to the
// property data when initializing bindings, avoiding expensive
// lookups by string (property name).

View File

@ -55,7 +55,7 @@
QT_BEGIN_NAMESPACE
QQmlCompiledData::QQmlCompiledData(QQmlEngine *engine)
: engine(engine), importCache(0), metaTypeId(-1), listMetaTypeId(-1), isRegisteredWithEngine(false),
: engine(engine), metaTypeId(-1), listMetaTypeId(-1), isRegisteredWithEngine(false),
totalBindingsCount(0), totalParserStatusCount(0)
{
Q_ASSERT(engine);
@ -88,9 +88,6 @@ QQmlCompiledData::~QQmlCompiledData()
for (int ii = 0; ii < scripts.count(); ++ii)
scripts.at(ii)->release();
if (importCache)
importCache->release();
}
void QQmlCompiledData::clear()

View File

@ -89,8 +89,6 @@ public:
QQmlEngine *engine;
QQmlTypeNameCache *importCache;
int metaTypeId;
int listMetaTypeId;
bool isRegisteredWithEngine;

View File

@ -166,7 +166,7 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI
context = new QQmlContextData;
context->isInternal = true;
context->imports = compiledData->importCache;
context->imports = compiledData->compilationUnit->importCache;
context->imports->addref();
context->initFromTypeCompilationUnit(compiledData->compilationUnit, subComponentIndex);
context->setParent(parentContext);
@ -1127,7 +1127,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo
if (customParser && obj->flags & QV4::CompiledData::Object::HasCustomParserBindings) {
customParser->engine = QQmlEnginePrivate::get(engine);
customParser->imports = compiledData->importCache;
customParser->imports = compiledData->compilationUnit->importCache;
QList<const QV4::CompiledData::Binding *> bindings;
const QV4::CompiledData::Object *obj = qmlUnit->objectAt(index);