aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Komissarov <abbapoh@gmail.com>2020-08-20 19:47:32 +0200
committerIvan Komissarov <ABBAPOH@gmail.com>2020-08-24 18:23:17 +0000
commitb928fc55c2670007e62da9995e6607be2472f7c1 (patch)
treee5a718e752d63bea9fd9c838dc40a743cea133f3
parent7f424ec15884e23ef56c7781f0a8de02ed016ae1 (diff)
Use std::optional in the m_existingModulePathCache function
... instead of the bool/QString pair Change-Id: Ied2911e438ffbfb6e5544b8cb99d8ee4077641aa Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/lib/corelib/language/moduleloader.cpp10
-rw-r--r--src/lib/corelib/language/moduleloader.h3
2 files changed, 6 insertions, 7 deletions
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index e1044d2a5..894ca32fd 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -3786,19 +3786,17 @@ QString ModuleLoader::findExistingModulePath(const QString &searchPath,
// isFileCaseCorrect is a very expensive call on macOS, so we cache the value for the
// modules and search paths we've already processed
auto &moduleInfo = m_existingModulePathCache[{searchPath, moduleName}];
- if (moduleInfo.first) // poor man's std::optional<QString>
- return moduleInfo.second;
+ if (moduleInfo)
+ return *moduleInfo;
for (const QString &moduleNamePart : moduleName) {
dirPath = FileInfo::resolvePath(dirPath, moduleNamePart);
if (!FileInfo::exists(dirPath) || !FileInfo::isFileCaseCorrect(dirPath)) {
- moduleInfo.first = true;
- return moduleInfo.second = QString();
+ return *(moduleInfo = QString());
}
}
- moduleInfo.first = true;
- return moduleInfo.second = dirPath;
+ return *(moduleInfo = dirPath);
}
QStringList ModuleLoader::findExistingModulePaths(
diff --git a/src/lib/corelib/language/moduleloader.h b/src/lib/corelib/language/moduleloader.h
index 942f93c83..2f6abb834 100644
--- a/src/lib/corelib/language/moduleloader.h
+++ b/src/lib/corelib/language/moduleloader.h
@@ -58,6 +58,7 @@
#include <map>
#include <memory>
+#include <optional>
#include <unordered_map>
#include <utility>
#include <vector>
@@ -414,7 +415,7 @@ private:
ItemReader *m_reader;
Evaluator *m_evaluator;
QMap<QString, QStringList> m_moduleDirListCache;
- QHash<std::pair<QString, QualifiedId>, std::pair<bool, QString>> m_existingModulePathCache;
+ QHash<std::pair<QString, QualifiedId>, std::optional<QString>> m_existingModulePathCache;
// The keys are file paths, the values are module prototype items accompanied by a profile.
std::unordered_map<QString, std::vector<std::pair<Item *, QString>>> m_modulePrototypes;