diff options
author | David Schulz <[email protected]> | 2023-09-07 15:38:17 +0200 |
---|---|---|
committer | David Schulz <[email protected]> | 2023-09-11 10:19:12 +0000 |
commit | 96c21b0e366870b66de81c7a1786c0d032aa585a (patch) | |
tree | 37f93e9e44973d68adca9f5adae4e6854d3dac21 | |
parent | 7f15f720ac47eaf15d2420b68fdeb65c2769f845 (diff) |
CppEditor: optimize CppModelManager projectPartForFile
Calling FilePath::canonicalPath is expensive on Windows, so only call it
if we cannot find the filePath in the cache and save the result to the
cache again. This reduces the time to parse the auto test for the Qt
Creator repository from 10s to 2s here. It also improves the performance
of various quickfixes and follow symbol of the built-in code model by a
similar factor.
Change-Id: I7025828e1b91f492825b10753e3b97e1c917fbfd
Reviewed-by: Christian Kandeler <[email protected]>
-rw-r--r-- | src/plugins/cppeditor/cppmodelmanager.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index a2f93635fea..231740899be 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -1465,8 +1465,11 @@ void CppModelManager::recalculateProjectPartMappings() for (const ProjectData &projectData : std::as_const(d->m_projectData)) { for (const ProjectPart::ConstPtr &projectPart : projectData.projectInfo->projectParts()) { d->m_projectPartIdToProjectProjectPart[projectPart->id()] = projectPart; - for (const ProjectFile &cxxFile : projectPart->files) - d->m_fileToProjectParts[cxxFile.path.canonicalPath()].append(projectPart); + for (const ProjectFile &cxxFile : projectPart->files) { + d->m_fileToProjectParts[cxxFile.path].append(projectPart); + if (FilePath canonical = cxxFile.path.canonicalPath(); canonical != cxxFile.path) + d->m_fileToProjectParts[canonical].append(projectPart); + } } } @@ -1639,8 +1642,16 @@ ProjectPart::ConstPtr CppModelManager::projectPartForId(const QString &projectPa QList<ProjectPart::ConstPtr> CppModelManager::projectPart(const FilePath &fileName) { - QReadLocker locker(&d->m_projectLock); - return d->m_fileToProjectParts.value(fileName.canonicalPath()); + { + QReadLocker locker(&d->m_projectLock); + auto it = d->m_fileToProjectParts.find(fileName); + if (it != d->m_fileToProjectParts.end()) + return it.value(); + } + const FilePath canonicalPath = fileName.canonicalPath(); + QWriteLocker locker(&d->m_projectLock); + auto it = d->m_fileToProjectParts.insert(fileName, d->m_fileToProjectParts.value(canonicalPath)); + return it.value(); } QList<ProjectPart::ConstPtr> CppModelManager::projectPartFromDependencies( @@ -1651,7 +1662,7 @@ QList<ProjectPart::ConstPtr> CppModelManager::projectPartFromDependencies( QReadLocker locker(&d->m_projectLock); for (const FilePath &dep : deps) - parts.unite(Utils::toSet(d->m_fileToProjectParts.value(dep.canonicalPath()))); + parts.unite(Utils::toSet(projectPart(dep))); return parts.values(); } |