Speed up closing all files in a project

Utilize the existing lookup function that does a binary search on the
sorted list of files.
This amends 03f76770e1.

Change-Id: Idea3e64a9764a9056511353b2df6a375ebcbbcbe
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2019-02-15 15:02:29 +01:00
parent da28d40030
commit caf6949548

View File

@@ -1856,18 +1856,15 @@ void ProjectExplorerPluginPrivate::setStartupProject(Project *project)
bool ProjectExplorerPluginPrivate::closeAllFilesInProject(const Project *project) bool ProjectExplorerPluginPrivate::closeAllFilesInProject(const Project *project)
{ {
QTC_ASSERT(project, return false); QTC_ASSERT(project, return false);
const Utils::FileNameList filesInProject = project->files(Project::AllFiles);
QList<IDocument *> openFiles = DocumentModel::openedDocuments(); QList<IDocument *> openFiles = DocumentModel::openedDocuments();
Utils::erase(openFiles, [filesInProject](const IDocument *doc) { Utils::erase(openFiles, [project](const IDocument *doc) {
return !filesInProject.contains(doc->filePath()); return !project->isKnownFile(doc->filePath());
}); });
for (const Project * const otherProject : SessionManager::projects()) { for (const Project * const otherProject : SessionManager::projects()) {
if (otherProject == project) if (otherProject == project)
continue; continue;
const Utils::FileNameList filesInOtherProject Utils::erase(openFiles, [otherProject](const IDocument *doc) {
= otherProject->files(Project::AllFiles); return otherProject->isKnownFile(doc->filePath());
Utils::erase(openFiles, [filesInOtherProject](const IDocument *doc) {
return filesInOtherProject.contains(doc->filePath());
}); });
} }
return EditorManager::closeDocuments(openFiles); return EditorManager::closeDocuments(openFiles);