diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2020-08-20 19:47:32 +0200 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2020-08-24 18:23:17 +0000 |
commit | b928fc55c2670007e62da9995e6607be2472f7c1 (patch) | |
tree | e5a718e752d63bea9fd9c838dc40a743cea133f3 | |
parent | 7f424ec15884e23ef56c7781f0a8de02ed016ae1 (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.cpp | 10 | ||||
-rw-r--r-- | src/lib/corelib/language/moduleloader.h | 3 |
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; |