Commit 7290c43d authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

C++: update project info once after finishing adding all project parts.

So that recalculating the information is not O(n^2) but linear.

Change-Id: I69903e0b5ad321d071804d782ad634a3f300e71a
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 9c1f44e9
...@@ -426,5 +426,6 @@ void AutotoolsProject::updateCppCodeModel() ...@@ -426,5 +426,6 @@ void AutotoolsProject::updateCppCodeModel()
foreach (Core::Id language, languages) foreach (Core::Id language, languages)
setProjectLanguage(language, true); setProjectLanguage(language, true);
pInfo.finish();
m_codeModelFuture = modelManager->updateProjectInfo(pInfo); m_codeModelFuture = modelManager->updateProjectInfo(pInfo);
} }
...@@ -350,6 +350,7 @@ bool CMakeProject::parseCMakeLists() ...@@ -350,6 +350,7 @@ bool CMakeProject::parseCMakeLists()
} }
m_codeModelFuture.cancel(); m_codeModelFuture.cancel();
pinfo.finish();
m_codeModelFuture = modelmanager->updateProjectInfo(pinfo); m_codeModelFuture = modelmanager->updateProjectInfo(pinfo);
} }
......
...@@ -104,6 +104,7 @@ public: ...@@ -104,6 +104,7 @@ public:
part->files.append(projectFile); part->files.append(projectFile);
} }
projectInfo.appendProjectPart(part); projectInfo.appendProjectPart(part);
projectInfo.finish();
} }
ModelManagerTestHelper *modelManagerTestHelper; ModelManagerTestHelper *modelManagerTestHelper;
...@@ -227,6 +228,7 @@ void CppToolsPlugin::test_modelmanager_paths_are_clean() ...@@ -227,6 +228,7 @@ void CppToolsPlugin::test_modelmanager_paths_are_clean()
<< HeaderPath(testDataDir.includeDir(false), HeaderPath::IncludePath) << HeaderPath(testDataDir.includeDir(false), HeaderPath::IncludePath)
<< HeaderPath(testDataDir.frameworksDir(false), HeaderPath::FrameworkPath); << HeaderPath(testDataDir.frameworksDir(false), HeaderPath::FrameworkPath);
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
mm->updateProjectInfo(pi); mm->updateProjectInfo(pi);
...@@ -265,6 +267,7 @@ void CppToolsPlugin::test_modelmanager_framework_headers() ...@@ -265,6 +267,7 @@ void CppToolsPlugin::test_modelmanager_framework_headers()
_("test_modelmanager_framework_headers.cpp")); _("test_modelmanager_framework_headers.cpp"));
part->files << ProjectFile(source, ProjectFile::CXXSource); part->files << ProjectFile(source, ProjectFile::CXXSource);
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
mm->updateProjectInfo(pi).waitForFinished(); mm->updateProjectInfo(pi).waitForFinished();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
...@@ -314,6 +317,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files() ...@@ -314,6 +317,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
<< HeaderPath(testDataDir.includeDir(false), HeaderPath::IncludePath); << HeaderPath(testDataDir.includeDir(false), HeaderPath::IncludePath);
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
QSet<QString> refreshedFiles = updateProjectInfo(mm, &helper, pi); QSet<QString> refreshedFiles = updateProjectInfo(mm, &helper, pi);
QCOMPARE(refreshedFiles.size(), 1); QCOMPARE(refreshedFiles.size(), 1);
...@@ -331,6 +335,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files() ...@@ -331,6 +335,7 @@ void CppToolsPlugin::test_modelmanager_refresh_also_includes_of_project_files()
part->projectDefines = QByteArray("#define TEST_DEFINE 1\n"); part->projectDefines = QByteArray("#define TEST_DEFINE 1\n");
pi.clearProjectParts(); pi.clearProjectParts();
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = updateProjectInfo(mm, &helper, pi);
...@@ -372,6 +377,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times() ...@@ -372,6 +377,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times()
part->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader)); part->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader));
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
mm->updateProjectInfo(pi); mm->updateProjectInfo(pi);
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
...@@ -391,6 +397,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times() ...@@ -391,6 +397,7 @@ void CppToolsPlugin::test_modelmanager_refresh_several_times()
part->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader)); part->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader));
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = updateProjectInfo(mm, &helper, pi);
QCOMPARE(refreshedFiles.size(), 3); QCOMPARE(refreshedFiles.size(), 3);
...@@ -435,6 +442,7 @@ void CppToolsPlugin::test_modelmanager_refresh_test_for_changes() ...@@ -435,6 +442,7 @@ void CppToolsPlugin::test_modelmanager_refresh_test_for_changes()
part->qtVersion = ProjectPart::Qt5; part->qtVersion = ProjectPart::Qt5;
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
// Reindexing triggers a reparsing thread // Reindexing triggers a reparsing thread
helper.resetRefreshedSourceFiles(); helper.resetRefreshedSourceFiles();
...@@ -473,6 +481,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed() ...@@ -473,6 +481,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed()
part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); part->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
part->files.append(ProjectFile(testHeader1, ProjectFile::CXXHeader)); part->files.append(ProjectFile(testHeader1, ProjectFile::CXXHeader));
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
QSet<QString> refreshedFiles; QSet<QString> refreshedFiles;
...@@ -495,6 +504,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed() ...@@ -495,6 +504,7 @@ void CppToolsPlugin::test_modelmanager_refresh_added_and_purge_removed()
newPart->files.append(ProjectFile(testCpp, ProjectFile::CXXSource)); newPart->files.append(ProjectFile(testCpp, ProjectFile::CXXSource));
newPart->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader)); newPart->files.append(ProjectFile(testHeader2, ProjectFile::CXXHeader));
pi.appendProjectPart(newPart); pi.appendProjectPart(newPart);
pi.finish();
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = updateProjectInfo(mm, &helper, pi);
...@@ -529,7 +539,9 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_ ...@@ -529,7 +539,9 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
part->qtVersion = ProjectPart::Qt5; part->qtVersion = ProjectPart::Qt5;
foreach (const ProjectFile &file, initialProjectFiles) foreach (const ProjectFile &file, initialProjectFiles)
part->files.append(file); part->files.append(file);
pi.clearProjectParts();
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
Document::Ptr document; Document::Ptr document;
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
...@@ -563,6 +575,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_ ...@@ -563,6 +575,7 @@ void CppToolsPlugin::test_modelmanager_refresh_timeStampModified_if_sourcefiles_
part->files.append(file); part->files.append(file);
pi.clearProjectParts(); pi.clearProjectParts();
pi.appendProjectPart(part); pi.appendProjectPart(part);
pi.finish();
refreshedFiles = updateProjectInfo(mm, &helper, pi); refreshedFiles = updateProjectInfo(mm, &helper, pi);
...@@ -835,6 +848,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project() ...@@ -835,6 +848,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
ProjectInfo pi = mm->projectInfo(project); ProjectInfo pi = mm->projectInfo(project);
pi.appendProjectPart(part1); pi.appendProjectPart(part1);
pi.appendProjectPart(part2); pi.appendProjectPart(part2);
pi.finish();
updateProjectInfo(mm, &helper, pi); updateProjectInfo(mm, &helper, pi);
QCOMPARE(mm->snapshot().size(), 4); QCOMPARE(mm->snapshot().size(), 4);
...@@ -910,6 +924,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers() ...@@ -910,6 +924,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
ProjectInfo pi = mm->projectInfo(project); ProjectInfo pi = mm->projectInfo(project);
pi.appendProjectPart(part1); pi.appendProjectPart(part1);
pi.appendProjectPart(part2); pi.appendProjectPart(part2);
pi.finish();
updateProjectInfo(mm, &helper, pi); updateProjectInfo(mm, &helper, pi);
QCOMPARE(mm->snapshot().size(), 4); QCOMPARE(mm->snapshot().size(), 4);
...@@ -990,6 +1005,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor() ...@@ -990,6 +1005,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
ProjectInfo pi = mm->projectInfo(project); ProjectInfo pi = mm->projectInfo(project);
pi.appendProjectPart(part1); pi.appendProjectPart(part1);
pi.appendProjectPart(part2); pi.appendProjectPart(part2);
pi.finish();
updateProjectInfo(mm, &helper, pi); updateProjectInfo(mm, &helper, pi);
......
...@@ -166,35 +166,36 @@ const QList<ProjectPart::Ptr> ProjectInfo::projectParts() const ...@@ -166,35 +166,36 @@ const QList<ProjectPart::Ptr> ProjectInfo::projectParts() const
void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part) void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part)
{ {
if (!part) if (part)
return; m_projectParts.append(part);
}
m_projectParts.append(part);
void ProjectInfo::finish()
{
typedef ProjectPart::HeaderPath HeaderPath; typedef ProjectPart::HeaderPath HeaderPath;
// Update header paths QSet<HeaderPath> incs;
QSet<HeaderPath> incs = QSet<HeaderPath>::fromList(m_headerPaths); foreach (const ProjectPart::Ptr &part, m_projectParts) {
foreach (const HeaderPath &hp, part->headerPaths) { // Update header paths
if (!incs.contains(hp)) { foreach (const HeaderPath &hp, part->headerPaths) {
incs.insert(hp); if (!incs.contains(hp)) {
m_headerPaths += hp; incs.insert(hp);
m_headerPaths += hp;
}
} }
}
// Update source files // Update source files
foreach (const ProjectFile &file, part->files) foreach (const ProjectFile &file, part->files)
m_sourceFiles.insert(file.path); m_sourceFiles.insert(file.path);
// Update defines // Update defines
if (!m_defines.isEmpty()) m_defines.append(part->toolchainDefines);
m_defines.append('\n'); m_defines.append(part->projectDefines);
m_defines.append(part->toolchainDefines); if (!part->projectConfigFile.isEmpty()) {
m_defines.append(part->projectDefines); m_defines.append('\n');
if (!part->projectConfigFile.isEmpty()) { m_defines += ProjectPart::readProjectConfigFile(part);
m_defines.append('\n'); m_defines.append('\n');
m_defines += ProjectPart::readProjectConfigFile(part); }
m_defines.append('\n');
} }
} }
......
...@@ -146,6 +146,7 @@ public: ...@@ -146,6 +146,7 @@ public:
const QList<ProjectPart::Ptr> projectParts() const; const QList<ProjectPart::Ptr> projectParts() const;
void appendProjectPart(const ProjectPart::Ptr &part); void appendProjectPart(const ProjectPart::Ptr &part);
void finish();
void clearProjectParts(); void clearProjectParts();
const ProjectPart::HeaderPaths headerPaths() const; const ProjectPart::HeaderPaths headerPaths() const;
......
...@@ -346,6 +346,7 @@ void GenericProject::refreshCppCodeModel() ...@@ -346,6 +346,7 @@ void GenericProject::refreshCppCodeModel()
foreach (Core::Id language, languages) foreach (Core::Id language, languages)
setProjectLanguage(language, true); setProjectLanguage(language, true);
pInfo.finish();
m_codeModelFuture = modelManager->updateProjectInfo(pInfo); m_codeModelFuture = modelManager->updateProjectInfo(pInfo);
} }
......
...@@ -741,6 +741,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj) ...@@ -741,6 +741,7 @@ void QbsProject::updateCppCodeModel(const qbs::ProjectData &prj)
if (pinfo.projectParts().isEmpty()) if (pinfo.projectParts().isEmpty())
return; return;
pinfo.finish();
QtSupport::UiCodeModelManager::update(this, uiFiles); QtSupport::UiCodeModelManager::update(this, uiFiles);
......
...@@ -620,6 +620,7 @@ void QmakeProject::updateCppCodeModel() ...@@ -620,6 +620,7 @@ void QmakeProject::updateCppCodeModel()
if (!cppPart->files.isEmpty()) if (!cppPart->files.isEmpty())
objcppPart->displayName += QLatin1String(" (ObjC++)"); objcppPart->displayName += QLatin1String(" (ObjC++)");
} }
pinfo.finish();
// Also update Ui Code Model Support: // Also update Ui Code Model Support:
QtSupport::UiCodeModelManager::update(this, uiCodeModelData); QtSupport::UiCodeModelManager::update(this, uiCodeModelData);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment