diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-08-22 17:17:57 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-08-22 17:17:57 +0200 |
commit | f1aff1f2d495562460a87d351e62c06109045a3a (patch) | |
tree | 93e4659421a3dc1fc664b539bf7e48ce28f64e84 /src/qml/qml/qqmltypeloader.cpp | |
parent | 842ada7b04d68cd37df2556bf50b48d8a5f39ec4 (diff) | |
parent | 46ed14da325c6c0382c0bc54cacc347d2d7f2b0a (diff) |
Merge remote-tracking branch 'origin/dev' into wip/new-backend
Change-Id: Iff06429f948ac6cdec77a9e5bb8c5375c56fe705
Diffstat (limited to 'src/qml/qml/qqmltypeloader.cpp')
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 93 |
1 files changed, 48 insertions, 45 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index de19fe3cd7..6601429be4 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -1779,23 +1779,21 @@ QString QQmlTypeLoader::absoluteFilePath(const QString &path) #endif int lastSlash = path.lastIndexOf(QLatin1Char('/')); - QStringRef dirPath(&path, 0, lastSlash); + QString dirPath(path.left(lastSlash)); - StringSet **fileSet = m_importDirCache.value(QHashedStringRef(dirPath.constData(), dirPath.length())); - if (!fileSet) { - QHashedString dirPathString(dirPath.toString()); - bool exists = QDir(dirPathString).exists(); - QStringHash<bool> *files = exists ? new QStringHash<bool> : 0; - m_importDirCache.insert(dirPathString, files); - fileSet = m_importDirCache.value(dirPathString); + if (!m_importDirCache.contains(dirPath)) { + bool exists = QDir(dirPath).exists(); + QCache<QString, bool> *entry = exists ? new QCache<QString, bool> : 0; + m_importDirCache.insert(dirPath, entry); } - if (!(*fileSet)) + QCache<QString, bool> *fileSet = m_importDirCache.object(dirPath); + if (!fileSet) return QString(); QString absoluteFilePath; - QHashedStringRef fileName(path.constData()+lastSlash+1, path.length()-lastSlash-1); + QString fileName(path.mid(lastSlash+1, path.length()-lastSlash-1)); - bool *value = (*fileSet)->value(fileName); + bool *value = fileSet->object(fileName); if (value) { if (*value) absoluteFilePath = path; @@ -1809,7 +1807,7 @@ QString QQmlTypeLoader::absoluteFilePath(const QString &path) #else exists = QFile::exists(path); #endif - (*fileSet)->insert(fileName.toString(), exists); + fileSet->insert(fileName, new bool(exists)); if (exists) absoluteFilePath = path; } @@ -1844,18 +1842,16 @@ bool QQmlTypeLoader::directoryExists(const QString &path) int length = path.length(); if (path.endsWith(QLatin1Char('/'))) --length; - QStringRef dirPath(&path, 0, length); + QString dirPath(path.left(length)); - StringSet **fileSet = m_importDirCache.value(QHashedStringRef(dirPath.constData(), dirPath.length())); - if (!fileSet) { - QHashedString dirPathString(dirPath.toString()); - bool exists = QDir(dirPathString).exists(); - QStringHash<bool> *files = exists ? new QStringHash<bool> : 0; - m_importDirCache.insert(dirPathString, files); - fileSet = m_importDirCache.value(dirPathString); + if (!m_importDirCache.contains(dirPath)) { + bool exists = QDir(dirPath).exists(); + QCache<QString, bool> *files = exists ? new QCache<QString, bool> : 0; + m_importDirCache.insert(dirPath, files); } - return (*fileSet); + QCache<QString, bool> *fileSet = m_importDirCache.object(dirPath); + return fileSet != 0; } @@ -1939,7 +1935,7 @@ void QQmlTypeLoader::clearCache() (*iter)->release(); for (QmldirCache::Iterator iter = m_qmldirCache.begin(), end = m_qmldirCache.end(); iter != end; ++iter) (*iter)->release(); - qDeleteAll(m_importDirCache); + qDeleteAll(m_importQmlDirCache); m_typeCache.clear(); @@ -1948,6 +1944,7 @@ void QQmlTypeLoader::clearCache() m_qmldirCache.clear(); m_importDirCache.clear(); m_importQmlDirCache.clear(); + QQmlMetaType::freeUnusedTypesAndCaches(); } void QQmlTypeLoader::updateTypeCacheTrimThreshold() @@ -1989,6 +1986,8 @@ void QQmlTypeLoader::trimCache() updateTypeCacheTrimThreshold(); + QQmlMetaType::freeUnusedTypesAndCaches(); + // TODO: release any scripts which are no longer referenced by any types } @@ -2014,7 +2013,7 @@ QString QQmlTypeData::TypeReference::qualifiedName() const if (!prefix.isEmpty()) { result = prefix + QLatin1Char('.'); } - result.append(type->qmlTypeName()); + result.append(type.qmlTypeName()); return result; } @@ -2169,8 +2168,8 @@ static bool addTypeReferenceChecksumsToHash(const QList<QQmlTypeData::TypeRefere if (typeRef.typeData) { const auto unit = typeRef.typeData->compilationUnit(); hash->addData(unit->data->md5Checksum, sizeof(unit->data->md5Checksum)); - } else if (typeRef.type) { - const auto propertyCache = QQmlEnginePrivate::get(engine)->cache(typeRef.type->metaObject()); + } else if (typeRef.type.isValid()) { + const auto propertyCache = QQmlEnginePrivate::get(engine)->cache(typeRef.type.metaObject()); bool ok = false; hash->addData(propertyCache->checksum(&ok)); if (!ok) @@ -2234,7 +2233,7 @@ void QQmlTypeData::done() const TypeReference &type = m_compositeSingletons.at(ii); Q_ASSERT(!type.typeData || type.typeData->isCompleteOrError()); if (type.typeData && type.typeData->isError()) { - QString typeName = type.type->qmlTypeName(); + QString typeName = type.type.qmlTypeName(); QList<QQmlError> errors = type.typeData->errors(); QQmlError error; @@ -2301,24 +2300,24 @@ void QQmlTypeData::done() } { - QQmlType *type = QQmlMetaType::qmlType(finalUrl(), true); + QQmlType type = QQmlMetaType::qmlType(finalUrl(), true); if (m_compiledData && m_compiledData->data->flags & QV4::CompiledData::Unit::IsSingleton) { - if (!type) { + if (!type.isValid()) { QQmlError error; error.setDescription(QQmlTypeLoader::tr("No matching type found, pragma Singleton files cannot be used by QQmlComponent.")); setError(error); return; - } else if (!type->isCompositeSingleton()) { + } else if (!type.isCompositeSingleton()) { QQmlError error; - error.setDescription(QQmlTypeLoader::tr("pragma Singleton used with a non composite singleton type %1").arg(type->qmlTypeName())); + error.setDescription(QQmlTypeLoader::tr("pragma Singleton used with a non composite singleton type %1").arg(type.qmlTypeName())); setError(error); return; } } else { // If the type is CompositeSingleton but there was no pragma Singleton in the // QML file, lets report an error. - if (type && type->isCompositeSingleton()) { - QString typeName = type->qmlTypeName(); + if (type.isValid() && type.isCompositeSingleton()) { + QString typeName = type.qmlTypeName(); setError(QQmlTypeLoader::tr("qmldir defines type as singleton, but no pragma Singleton found in type %1.").arg(typeName)); return; } @@ -2610,8 +2609,8 @@ void QQmlTypeData::resolveTypes() if (!resolveType(typeName, majorVersion, minorVersion, ref)) return; - if (ref.type->isCompositeSingleton()) { - ref.typeData = typeLoader()->getType(ref.type->sourceUrl()); + if (ref.type.isCompositeSingleton()) { + ref.typeData = typeLoader()->getType(ref.type.sourceUrl()); addDependency(ref.typeData); ref.prefix = csRef.prefix; @@ -2638,8 +2637,8 @@ void QQmlTypeData::resolveTypes() if (!resolveType(name, majorVersion, minorVersion, ref, unresolvedRef->location.line, unresolvedRef->location.column, reportErrors) && reportErrors) return; - if (ref.type && ref.type->isComposite()) { - ref.typeData = typeLoader()->getType(ref.type->sourceUrl()); + if (ref.type.isComposite()) { + ref.typeData = typeLoader()->getType(ref.type.sourceUrl()); addDependency(ref.typeData); } ref.majorVersion = majorVersion; @@ -2652,6 +2651,10 @@ void QQmlTypeData::resolveTypes() m_resolvedTypes.insert(unresolvedRef.key(), ref); } + + // ### this allows enums to work without explicit import or instantiation of the type + if (!m_implicitImportLoaded) + loadImplicitImport(); } QQmlCompileError QQmlTypeData::buildTypeResolutionCaches( @@ -2666,7 +2669,7 @@ QQmlCompileError QQmlTypeData::buildTypeResolutionCaches( // Add any Composite Singletons that were used to the import cache for (const QQmlTypeData::TypeReference &singleton: m_compositeSingletons) - (*typeNameCache)->add(singleton.type->qmlTypeName(), singleton.type->sourceUrl(), singleton.prefix); + (*typeNameCache)->add(singleton.type.qmlTypeName(), singleton.type.sourceUrl(), singleton.prefix); m_importCache.populateCache(*typeNameCache); @@ -2674,24 +2677,24 @@ QQmlCompileError QQmlTypeData::buildTypeResolutionCaches( for (auto resolvedType = m_resolvedTypes.constBegin(), end = m_resolvedTypes.constEnd(); resolvedType != end; ++resolvedType) { QScopedPointer<QV4::CompiledData::ResolvedTypeReference> ref(new QV4::CompiledData::ResolvedTypeReference); - QQmlType *qmlType = resolvedType->type; + QQmlType qmlType = resolvedType->type; if (resolvedType->typeData) { - if (resolvedType->needsCreation && qmlType->isCompositeSingleton()) { - return QQmlCompileError(resolvedType->location, tr("Composite Singleton Type %1 is not creatable.").arg(qmlType->qmlTypeName())); + if (resolvedType->needsCreation && qmlType.isCompositeSingleton()) { + return QQmlCompileError(resolvedType->location, tr("Composite Singleton Type %1 is not creatable.").arg(qmlType.qmlTypeName())); } ref->compilationUnit = resolvedType->typeData->compilationUnit(); - } else if (qmlType) { + } else if (qmlType.isValid()) { ref->type = qmlType; - Q_ASSERT(ref->type); + Q_ASSERT(ref->type.isValid()); - if (resolvedType->needsCreation && !ref->type->isCreatable()) { - QString reason = ref->type->noCreationReason(); + if (resolvedType->needsCreation && !ref->type.isCreatable()) { + QString reason = ref->type.noCreationReason(); if (reason.isEmpty()) reason = tr("Element is not creatable."); return QQmlCompileError(resolvedType->location, reason); } - if (ref->type->containsRevisionedAttributes()) { + if (ref->type.containsRevisionedAttributes()) { ref->typePropertyCache = engine->cache(ref->type, resolvedType->minorVersion); } |