diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-06 12:29:58 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-06 12:59:43 +0200 |
commit | c52a857c2b6b89abeddeee8489110ab9dd363e53 (patch) | |
tree | c1dd8127f8104f6318c1425bdbdac832a9ed9dc7 /src | |
parent | 3562e9da767d829396d97a1892bfbc8ef3ae8591 (diff) |
QmlCompiler: Unify and optimize directory imports
We don't need to import lowercase files as those can't be used anyway.
Also, the code was duplicated.
Change-Id: I5f24977e59a9b244b70362045524ed1e7849eeb8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qmlcompiler/qqmljsimporter.cpp | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp index 3a8507aa67..0ea310d64e 100644 --- a/src/qmlcompiler/qqmljsimporter.cpp +++ b/src/qmlcompiler/qqmljsimporter.cpp @@ -244,17 +244,7 @@ QQmlJSScope::Ptr QQmlJSImporter::localFile2ScopeTree(const QString &filePath) m_warnings.append(error); AvailableTypes types; - - QDirIterator it { - QFileInfo(filePath).canonicalPath(), - QStringList() << QLatin1String("*.qml"), - QDir::NoFilter - }; - while (it.hasNext()) { - QQmlJSScope::Ptr scope(localFile2ScopeTree(it.next())); - if (!scope->internalName().isEmpty()) - types.qmlNames.insert(scope->internalName(), scope); - } + types.qmlNames.insert(importDirectory(QFileInfo(filePath).canonicalPath())); const auto imports = typeReader.imports(); for (const auto &import : imports) @@ -272,7 +262,7 @@ QQmlJSScope::Ptr QQmlJSImporter::importFile(const QString &file) QQmlJSImporter::ImportedTypes QQmlJSImporter::importDirectory( const QString &directory, const QString &prefix) { - AvailableTypes result; + QHash<QString, QQmlJSScope::ConstPtr> qmlNames; QDirIterator it { directory, @@ -280,12 +270,15 @@ QQmlJSImporter::ImportedTypes QQmlJSImporter::importDirectory( QDir::NoFilter }; while (it.hasNext()) { - QQmlJSScope::Ptr scope(localFile2ScopeTree(it.next())); + it.next(); + if (!it.fileName().front().isUpper()) + continue; // Non-uppercase names cannot be imported anyway. + QQmlJSScope::Ptr scope(localFile2ScopeTree(it.filePath())); if (!scope->internalName().isEmpty()) - result.qmlNames.insert(prefixedName(prefix, scope->internalName()), scope); + qmlNames.insert(prefixedName(prefix, scope->internalName()), scope); } - return result.qmlNames; + return qmlNames; } QT_END_NAMESPACE |