diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-09-03 13:07:55 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-09-05 12:57:37 +0000 |
commit | 76f410452dd09489cc48197a0dd4d0bf95699647 (patch) | |
tree | 5043cab4d63676405668c1064bbfa5f6eda8882d /src/qml/qml/qqmlimport.cpp | |
parent | 1261fb2b89a8fa147f92c40d2476196d2745ca3f (diff) |
Optimize QQmlImportInstance::resolveType()
Optimize the case where the import is not a library and
tries to find the type on disk.
Avoid lots of conversions to and from QUrl and related
string processing.
Change-Id: Ife247d8adf5ec63127596f2c5ba16a56562ab84a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlimport.cpp')
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 035deea980..ee6484f0b7 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -674,6 +674,7 @@ bool QQmlImportInstance::setQmldirContent(const QString &resolvedUrl, const QQml { Q_ASSERT(resolvedUrl.endsWith(Slash)); url = resolvedUrl; + localDirectoryPath = QQmlFile::urlToLocalFileOrQrc(url); qmlDirComponents = qmldir.components(); @@ -811,21 +812,20 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedSt *type_return = returnType; return returnType.isValid(); } - } else if (!isLibrary) { + } else if (!isLibrary && !localDirectoryPath.isEmpty()) { QString qmlUrl; bool exists = false; const QString urlsToTry[2] = { - url + QString::fromRawData(type.constData(), type.length()) + dotqml_string, // Type -> Type.qml - url + QString::fromRawData(type.constData(), type.length()) + dotuidotqml_string // Type -> Type.ui.qml + typeStr + dotqml_string, // Type -> Type.qml + typeStr + dotuidotqml_string // Type -> Type.ui.qml }; for (uint i = 0; i < sizeof(urlsToTry) / sizeof(urlsToTry[0]); ++i) { - const QString url = urlsToTry[i]; - const QString localPath = QQmlFile::urlToLocalFileOrQrc(url); - exists = !typeLoader->absoluteFilePath(localPath).isEmpty(); + exists = typeLoader->fileExists(localDirectoryPath, urlsToTry[i]); if (exists) { +#if defined(Q_OS_MACOS) || defined(Q_OS_WIN) // don't let function.qml confuse the use of "new Function(...)" for example. - if (!QQml_isFileCaseCorrect(localPath)) { + if (!QQml_isFileCaseCorrect(localDirectoryPath + urlsToTry[i])) { exists = false; if (errors) { QQmlError caseError; @@ -834,7 +834,10 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedSt } break; } - qmlUrl = url; +#else + Q_UNUSED(errors); +#endif + qmlUrl = url + urlsToTry[i]; break; } } @@ -1433,6 +1436,7 @@ QQmlImportInstance *QQmlImportsPrivate::addImportToNamespace(QQmlImportNamespace QQmlImportInstance *import = new QQmlImportInstance; import->uri = uri; import->url = url; + import->localDirectoryPath = QQmlFile::urlToLocalFileOrQrc(url); import->majversion = vmaj; import->minversion = vmin; import->isLibrary = (type == QV4::CompiledData::Import::ImportLibrary); |