diff --git a/src/plugins/autotest/testconfiguration.cpp b/src/plugins/autotest/testconfiguration.cpp index 2b3740ead3e..195918e9abb 100644 --- a/src/plugins/autotest/testconfiguration.cpp +++ b/src/plugins/autotest/testconfiguration.cpp @@ -58,7 +58,7 @@ void completeBasicProjectInformation(Project *project, const QString &proFile, Q Project **targetProject) { CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); - QList projParts = cppMM->projectInfo(project).projectParts(); + QVector projParts = cppMM->projectInfo(project).projectParts(); if (displayName->isEmpty()) { foreach (const CppTools::ProjectPart::Ptr &part, projParts) { diff --git a/src/plugins/clangcodemodel/clangbackendipcintegration.cpp b/src/plugins/clangcodemodel/clangbackendipcintegration.cpp index 0b1d9895a7e..267e6302c64 100644 --- a/src/plugins/clangcodemodel/clangbackendipcintegration.cpp +++ b/src/plugins/clangcodemodel/clangbackendipcintegration.cpp @@ -387,7 +387,7 @@ static ClangBackEnd::ProjectPartContainer toProjectPartContainer( } static QVector toProjectPartContainers( - const QList projectParts) + const QVector projectParts) { QVector projectPartContainers; projectPartContainers.reserve(projectParts.size()); @@ -527,7 +527,7 @@ void IpcCommunicator::registerCurrentCodeModelUiHeaders() } } -void IpcCommunicator::registerProjectsParts(const QList projectParts) +void IpcCommunicator::registerProjectsParts(const QVector projectParts) { const auto projectPartContainers = toProjectPartContainers(projectParts); registerProjectPartsForEditor(projectPartContainers); diff --git a/src/plugins/clangcodemodel/clangbackendipcintegration.h b/src/plugins/clangcodemodel/clangbackendipcintegration.h index df69ef08130..f73f8035d9f 100644 --- a/src/plugins/clangcodemodel/clangbackendipcintegration.h +++ b/src/plugins/clangcodemodel/clangbackendipcintegration.h @@ -134,7 +134,7 @@ public: quint32 column, const QString &projectFilePath); - void registerProjectsParts(const QList projectParts); + void registerProjectsParts(const QVector projectParts); void updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document); void updateTranslationUnit(Core::IDocument *document); diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp index 404dc735e8f..0b0884b5981 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzerruncontrol.cpp @@ -371,7 +371,7 @@ static AnalyzeUnits unitsToAnalyzeFromCompilerCallData( return unitsToAnalyze; } -static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList projectParts) +static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QVector projectParts) { qCDebug(LOG) << "Taking arguments for analyzing from ProjectParts."; @@ -396,7 +396,7 @@ static AnalyzeUnits unitsToAnalyzeFromProjectParts(const QList } static QHash generateProjectFileToProjectPartMapping( - const QList &projectParts) + const QVector &projectParts) { QHash mapping; diff --git a/src/plugins/cpptools/cppcodemodelinspectordumper.cpp b/src/plugins/cpptools/cppcodemodelinspectordumper.cpp index 710cfda92ba..a0fc9bb4d86 100644 --- a/src/plugins/cpptools/cppcodemodelinspectordumper.cpp +++ b/src/plugins/cpptools/cppcodemodelinspectordumper.cpp @@ -481,7 +481,7 @@ void Dumper::dumpProjectInfos( const QList &projectInfos) m_out << i1 << "Project " << project->displayName() << " (" << project->projectFilePath().toUserOutput() << "){{{2\n"; - const QList projectParts = info.projectParts(); + const QVector projectParts = info.projectParts(); foreach (const ProjectPart::Ptr &part, projectParts) { QString projectName = QLatin1String(""); QString projectFilePath = QLatin1String(""); diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 4334af3b2e1..890fe2b1a7c 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #include @@ -683,13 +682,6 @@ void CppModelManager::removeFilesFromSnapshot(const QSet &filesToRemove d->m_snapshot.remove(i.next()); } -static QSet projectPartIds(const QSet &projectParts) -{ - return Utils::transform(projectParts, [](const ProjectPart::Ptr &projectPart) { - return projectPart->id(); - }); -} - class ProjectInfoComparer { public: @@ -721,8 +713,8 @@ public: QStringList removedProjectParts() { - QSet removed = projectPartIds(m_old.projectParts().toSet()); - removed.subtract(projectPartIds(m_new.projectParts().toSet())); + QSet removed = projectPartIds(m_old.projectParts()); + removed.subtract(projectPartIds(m_new.projectParts())); return removed.toList(); } @@ -743,6 +735,17 @@ public: return CppModelManager::timeStampModifiedFiles(documentsToCheck); } +private: + static QSet projectPartIds(const QVector &projectParts) + { + QSet ids; + + foreach (const ProjectPart::Ptr &projectPart, projectParts) + ids.insert(projectPart->id()); + + return ids; + } + private: const ProjectInfo &m_old; const QSet m_oldSourceFiles; diff --git a/src/plugins/cpptools/projectinfo.cpp b/src/plugins/cpptools/projectinfo.cpp index 1ac8ee35092..c3f62e4f336 100644 --- a/src/plugins/cpptools/projectinfo.cpp +++ b/src/plugins/cpptools/projectinfo.cpp @@ -29,28 +29,56 @@ namespace CppTools { -ProjectInfo::ProjectInfo() -{} - ProjectInfo::ProjectInfo(QPointer project) : m_project(project) -{} +{ +} + +bool ProjectInfo::isValid() const +{ + return !m_project.isNull(); +} + +QPointer ProjectInfo::project() const +{ + return m_project; +} + +const QVector ProjectInfo::projectParts() const +{ + return m_projectParts; +} + +const QSet ProjectInfo::sourceFiles() const +{ + return m_sourceFiles; +} + +void ProjectInfo::setCompilerCallData(const CompilerCallData &data) +{ + m_compilerCallData = data; +} + +ProjectInfo::CompilerCallData ProjectInfo::compilerCallData() const +{ + return m_compilerCallData; +} static bool operator==(const ProjectInfo::CompilerCallGroup &first, const ProjectInfo::CompilerCallGroup &second) { return first.groupId == second.groupId - && first.callsPerSourceFile == second.callsPerSourceFile; + && first.callsPerSourceFile == second.callsPerSourceFile; } bool ProjectInfo::operator ==(const ProjectInfo &other) const { return m_project == other.m_project - && m_projectParts == other.m_projectParts - && m_compilerCallData == other.m_compilerCallData - && m_headerPaths == other.m_headerPaths - && m_sourceFiles == other.m_sourceFiles - && m_defines == other.m_defines; + && m_projectParts == other.m_projectParts + && m_compilerCallData == other.m_compilerCallData + && m_headerPaths == other.m_headerPaths + && m_sourceFiles == other.m_sourceFiles + && m_defines == other.m_defines; } bool ProjectInfo::operator !=(const ProjectInfo &other) const @@ -73,40 +101,25 @@ bool ProjectInfo::configurationOrFilesChanged(const ProjectInfo &other) const return configurationChanged(other) || m_sourceFiles != other.m_sourceFiles; } -bool ProjectInfo::isValid() const +void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &projectPart) { - return !m_project.isNull(); -} - -QPointer ProjectInfo::project() const -{ - return m_project; -} - -const QList ProjectInfo::projectParts() const -{ - return m_projectParts; -} - -void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part) -{ - if (part) - m_projectParts.append(part); + if (projectPart) + m_projectParts.append(projectPart); } void ProjectInfo::finish() { - typedef ProjectPartHeaderPath HeaderPath; + QSet uniqueHeaderPaths; - QSet incs; foreach (const ProjectPart::Ptr &part, m_projectParts) { part->updateLanguageFeatures(); + // Update header paths - foreach (const HeaderPath &hp, part->headerPaths) { - if (!incs.contains(hp)) { - incs.insert(hp); - m_headerPaths += hp; - } + foreach (const ProjectPartHeaderPath &headerPath, part->headerPaths) { + const int count = uniqueHeaderPaths.count(); + uniqueHeaderPaths.insert(headerPath); + if (count < uniqueHeaderPaths.count()) + m_headerPaths += headerPath; } // Update source files @@ -124,29 +137,4 @@ void ProjectInfo::finish() } } -const ProjectPartHeaderPaths ProjectInfo::headerPaths() const -{ - return m_headerPaths; -} - -const QSet ProjectInfo::sourceFiles() const -{ - return m_sourceFiles; -} - -const QByteArray ProjectInfo::defines() const -{ - return m_defines; -} - -void ProjectInfo::setCompilerCallData(const CompilerCallData &data) -{ - m_compilerCallData = data; -} - -ProjectInfo::CompilerCallData ProjectInfo::compilerCallData() const -{ - return m_compilerCallData; -} - } // namespace CppTools diff --git a/src/plugins/cpptools/projectinfo.h b/src/plugins/cpptools/projectinfo.h index 3f84215f8b5..758775d4929 100644 --- a/src/plugins/cpptools/projectinfo.h +++ b/src/plugins/cpptools/projectinfo.h @@ -32,32 +32,21 @@ #include #include #include +#include namespace CppTools { class CPPTOOLS_EXPORT ProjectInfo { public: - ProjectInfo(); + ProjectInfo() = default; ProjectInfo(QPointer project); bool isValid() const; - bool operator ==(const ProjectInfo &other) const; - bool operator !=(const ProjectInfo &other) const; - bool definesChanged(const ProjectInfo &other) const; - bool configurationChanged(const ProjectInfo &other) const; - bool configurationOrFilesChanged(const ProjectInfo &other) const; - QPointer project() const; - const QList projectParts() const; - - void appendProjectPart(const ProjectPart::Ptr &part); - void finish(); - - const ProjectPartHeaderPaths headerPaths() const; + const QVector projectParts() const; const QSet sourceFiles() const; - const QByteArray defines() const; struct CompilerCallGroup { using CallsPerSourceFile = QHash>; @@ -69,10 +58,22 @@ public: void setCompilerCallData(const CompilerCallData &data); CompilerCallData compilerCallData() const; + // Comparisons + bool operator ==(const ProjectInfo &other) const; + bool operator !=(const ProjectInfo &other) const; + bool definesChanged(const ProjectInfo &other) const; + bool configurationChanged(const ProjectInfo &other) const; + bool configurationOrFilesChanged(const ProjectInfo &other) const; + + // Construction + void appendProjectPart(const ProjectPart::Ptr &projectPart); + void finish(); + private: QPointer m_project; - QList m_projectParts; + QVector m_projectParts; CompilerCallData m_compilerCallData; + // The members below are (re)calculated from the project parts with finish() ProjectPartHeaderPaths m_headerPaths; QSet m_sourceFiles; diff --git a/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp b/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp index 50a559bcdd5..00c1780e6a8 100644 --- a/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp +++ b/src/plugins/genericprojectmanager/genericprojectplugin_test.cpp @@ -101,7 +101,7 @@ void GenericProjectPlugin::test_mixed1() QVERIFY(pInfo.isValid()); QCOMPARE(pInfo.projectParts().size(), 3); - QList parts = pInfo.projectParts(); + QVector parts = pInfo.projectParts(); std::sort(parts.begin(), parts.end(), [](const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) { return p1->displayName < p2->displayName; @@ -150,7 +150,7 @@ void GenericProjectPlugin::test_mixed2() QVERIFY(pInfo.isValid()); QCOMPARE(pInfo.projectParts().size(), 2); - QList parts = pInfo.projectParts(); + QVector parts = pInfo.projectParts(); std::sort(parts.begin(), parts.end(), [](const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) { return p1->displayName < p2->displayName; diff --git a/tests/unit/unittest/cppbaseprojectpartbuilder-test.cpp b/tests/unit/unittest/cppbaseprojectpartbuilder-test.cpp index 6b7a2c39c6f..3fdc4387705 100644 --- a/tests/unit/unittest/cppbaseprojectpartbuilder-test.cpp +++ b/tests/unit/unittest/cppbaseprojectpartbuilder-test.cpp @@ -195,7 +195,7 @@ TEST_F(BaseProjectPartBuilder, ProjectFileKindsMatchProjectPartVersion) builder.createProjectPartsForFiles(QStringList() << "foo.h"); - const QList projectParts = projectInfo.projectParts(); + const QVector projectParts = projectInfo.projectParts(); ASSERT_THAT(projectParts.size(), Eq(4)); ASSERT_THAT(projectParts.at(0)->languageVersion, Eq(ProjectPart::LatestCVersion)); ASSERT_THAT(projectParts.at(0)->files.at(0).kind, Eq(ProjectFile::CHeader));