aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <[email protected]>2023-06-22 14:58:11 +0200
committerChristian Kandeler <[email protected]>2023-06-23 09:51:54 +0000
commitcf6bd7e0124f31374f3a4abd05d14199d201961b (patch)
tree90ce2081bdea0b7bece256bd00c0d0476171e00f /src/libs/qmljs/qmljsmodelmanagerinterface.cpp
parentae33199d046902bb9877810df2dbc590b083ef3c (diff)
Fix occurrences of the contains/insert anti-pattern
Introduce and make use of Utils::insert() for QSet with a return value that indicates whether insertion actually happened. Change-Id: I655e4bc3553b74fea5ae8956205e4d8070118d63 Reviewed-by: hjk <[email protected]> Reviewed-by: Eike Ziller <[email protected]>
Diffstat (limited to 'src/libs/qmljs/qmljsmodelmanagerinterface.cpp')
-rw-r--r--src/libs/qmljs/qmljsmodelmanagerinterface.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
index 66a670d1b8a..93b8ca35e71 100644
--- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
+++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
@@ -734,10 +734,9 @@ static void findNewImplicitImports(const Document::Ptr &doc,
// scan files that could be implicitly imported
// it's important we also do this for JS files, otherwise the isEmpty check will fail
if (snapshot.documentsInDirectory(doc->path()).isEmpty()) {
- if (!scannedPaths->contains(doc->path())) {
+ if (Utils::insert(*scannedPaths, doc->path())) {
*importedFiles += filesInDirectoryForLanguages(doc->path(),
doc->language().companionLanguages());
- scannedPaths->insert(doc->path());
}
}
}
@@ -757,11 +756,10 @@ static void findNewFileImports(const Document::Ptr &doc,
*importedFiles += importPath;
} else if (import.type() == ImportType::Directory) {
if (snapshot.documentsInDirectory(importPath).isEmpty()) {
- if (!scannedPaths->contains(importPath)) {
+ if (Utils::insert(*scannedPaths, importPath)) {
*importedFiles
+= filesInDirectoryForLanguages(importPath,
doc->language().companionLanguages());
- scannedPaths->insert(importPath);
}
}
} else if (import.type() == ImportType::QrcFile) {
@@ -890,10 +888,9 @@ static bool findNewQmlLibraryInPath(const Utils::FilePath &path,
if (!component.fileName.isEmpty()) {
const FilePath componentFile = path.pathAppended(component.fileName);
const FilePath path = componentFile.absolutePath().cleanPath();
- if (!scannedPaths->contains(path)) {
+ if (Utils::insert(*scannedPaths, path)) {
*importedFiles += filesInDirectoryForLanguages(path, Dialect(Dialect::AnyLanguage)
.companionLanguages());
- scannedPaths->insert(path);
}
}
}
@@ -1110,10 +1107,9 @@ void ModelManagerInterface::importScanAsync(QPromise<void> &promise, const Worki
QMutexLocker l(&modelManager->m_mutex);
for (const auto &path : paths) {
Utils::FilePath cPath = path.path().cleanPath();
- if (!forceRescan && modelManager->m_scannedPaths.contains(cPath))
+ if (!forceRescan && !Utils::insert(modelManager->m_scannedPaths, cPath))
continue;
pathsToScan.append({cPath, 0, path.language()});
- modelManager->m_scannedPaths.insert(cPath);
}
}
const int maxScanDepth = 5;