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/qqmltypeloader.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/qqmltypeloader.cpp')
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index b0db031bf9..0b0ee9cb9a 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -1862,6 +1862,52 @@ QString QQmlTypeLoader::absoluteFilePath(const QString &path) return absoluteFilePath; } +bool QQmlTypeLoader::fileExists(const QString &path, const QString &file) +{ + if (path.isEmpty()) + return false; + Q_ASSERT(path.endsWith(QLatin1Char('/'))); + if (path.at(0) == QLatin1Char(':')) { + // qrc resource + QFileInfo fileInfo(path + file); + return fileInfo.isFile(); + } else if (path.count() > 3 && path.at(3) == QLatin1Char(':') && + path.startsWith(QLatin1String("qrc"), Qt::CaseInsensitive)) { + // qrc resource url + QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(path + file)); + return fileInfo.isFile(); + } +#if defined(Q_OS_ANDROID) + else if (path.count() > 7 && path.at(6) == QLatin1Char(':') && path.at(7) == QLatin1Char('/') && + path.startsWith(QLatin1String("assets"), Qt::CaseInsensitive)) { + // assets resource url + QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(path + file)); + return fileInfo.isFile(); + } +#endif + + LockHolder<QQmlTypeLoader> holder(this); + if (!m_importDirCache.contains(path)) { + bool exists = QDir(path).exists(); + QCache<QString, bool> *entry = exists ? new QCache<QString, bool> : nullptr; + m_importDirCache.insert(path, entry); + } + QCache<QString, bool> *fileSet = m_importDirCache.object(path); + if (!fileSet) + return false; + + QString absoluteFilePath; + + bool *value = fileSet->object(file); + if (value) { + return *value; + } else { + bool exists = QFile::exists(path + file); + fileSet->insert(file, new bool(exists)); + return exists; + } +} + /*! Returns true if the path is a directory via a directory cache. Cache is |