logic: improved "prepare indexing" performance for cxx sourcegroups

* improved performance of "prepare indexing" step for all cxx source groups except empty
* unified code for filtering to contained file paths of source groups
* cleaned up code of SourceGroupFactoryModules
This commit is contained in:
mlangkabel
2018-07-31 14:17:14 +02:00
parent 445e7f339e
commit 40bd5ceb5a
13 changed files with 108 additions and 146 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ class SourceGroupFactoryModule
public: public:
virtual ~SourceGroupFactoryModule(); virtual ~SourceGroupFactoryModule();
virtual bool supports(SourceGroupType type) const = 0; virtual bool supports(SourceGroupType type) const = 0;
virtual std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) = 0; virtual std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) const = 0;
}; };
#endif // SOURCE_GROUP_FACTORY_MODULE_H #endif // SOURCE_GROUP_FACTORY_MODULE_H
+2
View File
@@ -107,6 +107,8 @@ add_files(
utility/IncludeDirective.h utility/IncludeDirective.h
utility/IncludeProcessing.cpp utility/IncludeProcessing.cpp
utility/IncludeProcessing.h utility/IncludeProcessing.h
utility/utilitySourceGroupCxx.cpp
utility/utilitySourceGroupCxx.h
LanguagePackageCxx.cpp LanguagePackageCxx.cpp
LanguagePackageCxx.h LanguagePackageCxx.h
+5 -38
View File
@@ -7,6 +7,7 @@
#include "settings/ApplicationSettings.h" #include "settings/ApplicationSettings.h"
#include "utility/messaging/type/MessageStatus.h" #include "utility/messaging/type/MessageStatus.h"
#include "utility/utility.h" #include "utility/utility.h"
#include "utility/utilitySourceGroupCxx.h"
#include "Application.h" #include "Application.h"
SourceGroupCxxCdb::SourceGroupCxxCdb(std::shared_ptr<SourceGroupSettingsCxxCdb> settings) SourceGroupCxxCdb::SourceGroupCxxCdb(std::shared_ptr<SourceGroupSettingsCxxCdb> settings)
@@ -38,46 +39,12 @@ bool SourceGroupCxxCdb::prepareIndexing()
std::set<FilePath> SourceGroupCxxCdb::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const std::set<FilePath> SourceGroupCxxCdb::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
{ {
std::set<FilePath> containedFilePaths; return utility::filterToContainedFilePaths(
filePaths,
const std::set<FilePath> indexedPaths = utility::concat(
getAllSourceFilePaths(), getAllSourceFilePaths(),
utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()) utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()),
m_settings->getExcludeFiltersExpandedAndAbsolute()
); );
const std::vector<FilePathFilter> excludeFilters = m_settings->getExcludeFiltersExpandedAndAbsolute();
for (const FilePath& filePath : filePaths)
{
bool isInIndexedPaths = false;
for (const FilePath& indexedPath : indexedPaths)
{
if (indexedPath == filePath || indexedPath.contains(filePath))
{
isInIndexedPaths = true;
break;
}
}
if (isInIndexedPaths)
{
for (const FilePathFilter& excludeFilter : excludeFilters)
{
if (excludeFilter.isMatching(filePath))
{
isInIndexedPaths = false;
break;
}
}
}
if (isInIndexedPaths)
{
containedFilePaths.insert(filePath);
}
}
return containedFilePaths;
} }
std::set<FilePath> SourceGroupCxxCdb::getAllSourceFilePaths() const std::set<FilePath> SourceGroupCxxCdb::getAllSourceFilePaths() const
@@ -6,6 +6,7 @@
#include "utility/messaging/type/MessageStatus.h" #include "utility/messaging/type/MessageStatus.h"
#include "utility/codeblocks/CodeblocksProject.h" #include "utility/codeblocks/CodeblocksProject.h"
#include "utility/utility.h" #include "utility/utility.h"
#include "utility/utilitySourceGroupCxx.h"
#include "Application.h" #include "Application.h"
SourceGroupCxxCodeblocks::SourceGroupCxxCodeblocks(std::shared_ptr<SourceGroupSettingsCxxCodeblocks> settings) SourceGroupCxxCodeblocks::SourceGroupCxxCodeblocks(std::shared_ptr<SourceGroupSettingsCxxCodeblocks> settings)
@@ -37,46 +38,12 @@ bool SourceGroupCxxCodeblocks::prepareIndexing()
std::set<FilePath> SourceGroupCxxCodeblocks::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const std::set<FilePath> SourceGroupCxxCodeblocks::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
{ {
std::set<FilePath> containedFilePaths; return utility::filterToContainedFilePaths(
filePaths,
const std::set<FilePath> indexedPaths = utility::concat( getAllSourceFilePaths(),
getAllSourceFilePaths(), utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()),
utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()) m_settings->getExcludeFiltersExpandedAndAbsolute()
); );
const std::vector<FilePathFilter> excludeFilters = m_settings->getExcludeFiltersExpandedAndAbsolute();
for (const FilePath& filePath : filePaths)
{
bool isInIndexedPaths = false;
for (const FilePath& indexedPath : indexedPaths)
{
if (indexedPath == filePath || indexedPath.contains(filePath))
{
isInIndexedPaths = true;
break;
}
}
if (isInIndexedPaths)
{
for (const FilePathFilter& excludeFilter : excludeFilters)
{
if (excludeFilter.isMatching(filePath))
{
isInIndexedPaths = false;
break;
}
}
}
if (isInIndexedPaths)
{
containedFilePaths.insert(filePath);
}
}
return containedFilePaths;
} }
std::set<FilePath> SourceGroupCxxCodeblocks::getAllSourceFilePaths() const std::set<FilePath> SourceGroupCxxCodeblocks::getAllSourceFilePaths() const
+8 -33
View File
@@ -8,6 +8,7 @@
#include "settings/SourceGroupSettingsWithCStandard.h" #include "settings/SourceGroupSettingsWithCStandard.h"
#include "utility/file/FileManager.h" #include "utility/file/FileManager.h"
#include "utility/utility.h" #include "utility/utility.h"
#include "utility/utilitySourceGroupCxx.h"
SourceGroupCxxEmpty::SourceGroupCxxEmpty(std::shared_ptr<SourceGroupSettingsCxx> settings) SourceGroupCxxEmpty::SourceGroupCxxEmpty(std::shared_ptr<SourceGroupSettingsCxx> settings)
: m_settings(settings) : m_settings(settings)
@@ -16,8 +17,6 @@ SourceGroupCxxEmpty::SourceGroupCxxEmpty(std::shared_ptr<SourceGroupSettingsCxx>
std::set<FilePath> SourceGroupCxxEmpty::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const std::set<FilePath> SourceGroupCxxEmpty::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
{ {
std::set<FilePath> containedFilePaths;
std::vector<FilePath> indexedPaths; std::vector<FilePath> indexedPaths;
std::vector<FilePathFilter> excludeFilters; std::vector<FilePathFilter> excludeFilters;
if (std::shared_ptr<SourceGroupSettingsCEmpty> settings = if (std::shared_ptr<SourceGroupSettingsCEmpty> settings =
@@ -33,36 +32,12 @@ std::set<FilePath> SourceGroupCxxEmpty::filterToContainedFilePaths(const std::se
excludeFilters = settings->getExcludeFiltersExpandedAndAbsolute(); excludeFilters = settings->getExcludeFiltersExpandedAndAbsolute();
} }
for (const FilePath& filePath : filePaths) return utility::filterToContainedFilePaths(
{ filePaths,
bool isInIndexedPaths = false; utility::toSet(indexedPaths),
for (const FilePath& indexedPath : indexedPaths) std::set<FilePath>(),
{ excludeFilters
if (indexedPath == filePath || indexedPath.contains(filePath)) );
{
isInIndexedPaths = true;
break;
}
}
if (isInIndexedPaths)
{
for (const FilePathFilter& excludeFilter : excludeFilters)
{
if (excludeFilter.isMatching(filePath))
{
isInIndexedPaths = false;
break;
}
}
}
if (isInIndexedPaths)
{
containedFilePaths.insert(filePath);
}
}
return containedFilePaths;
} }
std::set<FilePath> SourceGroupCxxEmpty::getAllSourceFilePaths() const std::set<FilePath> SourceGroupCxxEmpty::getAllSourceFilePaths() const
@@ -86,7 +61,7 @@ std::set<FilePath> SourceGroupCxxEmpty::getAllSourceFilePaths() const
settings->getSourceExtensions() settings->getSourceExtensions()
); );
} }
return fileManager.getAllSourceFilePaths(); return fileManager.getAllSourceFilePaths();
} }
@@ -6,6 +6,7 @@
#include "utility/messaging/type/MessageStatus.h" #include "utility/messaging/type/MessageStatus.h"
#include "utility/sonargraph/SonargraphProject.h" #include "utility/sonargraph/SonargraphProject.h"
#include "utility/utility.h" #include "utility/utility.h"
#include "utility/utilitySourceGroupCxx.h"
#include "Application.h" #include "Application.h"
SourceGroupCxxSonargraph::SourceGroupCxxSonargraph(std::shared_ptr<SourceGroupSettingsCxxSonargraph> settings) SourceGroupCxxSonargraph::SourceGroupCxxSonargraph(std::shared_ptr<SourceGroupSettingsCxxSonargraph> settings)
@@ -37,26 +38,12 @@ bool SourceGroupCxxSonargraph::prepareIndexing()
std::set<FilePath> SourceGroupCxxSonargraph::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const std::set<FilePath> SourceGroupCxxSonargraph::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
{ {
std::set<FilePath> containedFilePaths; return utility::filterToContainedFilePaths(
filePaths,
const std::set<FilePath> indexedPaths = utility::concat(
getAllSourceFilePaths(), getAllSourceFilePaths(),
utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()) utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()),
std::vector<FilePathFilter>()
); );
for (const FilePath& filePath : filePaths)
{
for (const FilePath& indexedPath : indexedPaths)
{
if (indexedPath == filePath || indexedPath.contains(filePath))
{
containedFilePaths.insert(filePath);
break;
}
}
}
return containedFilePaths;
} }
std::set<FilePath> SourceGroupCxxSonargraph::getAllSourceFilePaths() const std::set<FilePath> SourceGroupCxxSonargraph::getAllSourceFilePaths() const
@@ -10,10 +10,6 @@
#include "settings/SourceGroupSettingsCppEmpty.h" #include "settings/SourceGroupSettingsCppEmpty.h"
#include "settings/SourceGroupSettingsCxxSonargraph.h" #include "settings/SourceGroupSettingsCxxSonargraph.h"
SourceGroupFactoryModuleCxx::~SourceGroupFactoryModuleCxx()
{
}
bool SourceGroupFactoryModuleCxx::supports(SourceGroupType type) const bool SourceGroupFactoryModuleCxx::supports(SourceGroupType type) const
{ {
switch (type) switch (type)
@@ -30,7 +26,7 @@ bool SourceGroupFactoryModuleCxx::supports(SourceGroupType type) const
return false; return false;
} }
std::shared_ptr<SourceGroup> SourceGroupFactoryModuleCxx::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) std::shared_ptr<SourceGroup> SourceGroupFactoryModuleCxx::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) const
{ {
std::shared_ptr<SourceGroup> sourceGroup; std::shared_ptr<SourceGroup> sourceGroup;
if (std::shared_ptr<SourceGroupSettingsCxxCdb> cxxSettings = std::dynamic_pointer_cast<SourceGroupSettingsCxxCdb>(settings)) if (std::shared_ptr<SourceGroupSettingsCxxCdb> cxxSettings = std::dynamic_pointer_cast<SourceGroupSettingsCxxCdb>(settings))
@@ -6,9 +6,8 @@
class SourceGroupFactoryModuleCxx: public SourceGroupFactoryModule class SourceGroupFactoryModuleCxx: public SourceGroupFactoryModule
{ {
public: public:
virtual ~SourceGroupFactoryModuleCxx(); bool supports(SourceGroupType type) const override;
virtual bool supports(SourceGroupType type) const; std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) const override;
virtual std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings);
}; };
#endif // SOURCE_GROUP_FACTORY_MODULE_CXX_H #endif // SOURCE_GROUP_FACTORY_MODULE_CXX_H
+1 -1
View File
@@ -42,7 +42,7 @@ private:
); );
static FilePath resolveIncludeDirective( static FilePath resolveIncludeDirective(
const IncludeDirective& includeDirective, const IncludeDirective& includeDirective,
const std::set<FilePath>& headerSearchDirectories const std::set<FilePath>& headerSearchDirectories
); );
@@ -0,0 +1,55 @@
#include "utility/utilitySourceGroupCxx.h"
std::set<FilePath> utility::filterToContainedFilePaths(
const std::set<FilePath> filePaths,
const std::set<FilePath>& indexedSourcePaths,
const std::set<FilePath>& indexedHeaderPaths,
const std::vector<FilePathFilter> excludeFilters)
{
std::set<FilePath> containedFilePaths;
for (const FilePath& filePath : filePaths)
{
bool isInIndexedPaths = false;
{
for (const FilePath& indexedHeaderPath : indexedHeaderPaths)
{
if (indexedHeaderPath == filePath || indexedHeaderPath.contains(filePath))
{
isInIndexedPaths = true;
break;
}
}
}
if (!isInIndexedPaths)
{
for (const FilePath& indexedSourcePath : indexedSourcePaths)
{
if (indexedSourcePath == filePath)
{
isInIndexedPaths = true;
break;
}
}
}
if (isInIndexedPaths)
{
for (const FilePathFilter& excludeFilter : excludeFilters)
{
if (excludeFilter.isMatching(filePath))
{
isInIndexedPaths = false;
break;
}
}
}
if (isInIndexedPaths)
{
containedFilePaths.insert(filePath);
}
}
return containedFilePaths;
}
@@ -0,0 +1,19 @@
#ifndef UTILITY_SOURCE_GROUP_CXX_H
#define UTILITY_SOURCE_GROUP_CXX_H
#include <set>
#include <vector>
#include "utility/file/FilePath.h"
#include "utility/file/FilePathFilter.h"
namespace utility
{
std::set<FilePath> filterToContainedFilePaths(
const std::set<FilePath> filePaths,
const std::set<FilePath>& indexedSourcePaths,
const std::set<FilePath>& indexedHeaderPaths,
const std::vector<FilePathFilter> excludeFilters);
}
#endif // UTILITY_SOURCE_GROUP_CXX_H
@@ -9,10 +9,6 @@
#include "settings/SourceGroupSettingsJavaMaven.h" #include "settings/SourceGroupSettingsJavaMaven.h"
#include "settings/SourceGroupSettingsJavaSonargraph.h" #include "settings/SourceGroupSettingsJavaSonargraph.h"
SourceGroupFactoryModuleJava::~SourceGroupFactoryModuleJava()
{
}
bool SourceGroupFactoryModuleJava::supports(SourceGroupType type) const bool SourceGroupFactoryModuleJava::supports(SourceGroupType type) const
{ {
switch (type) switch (type)
@@ -28,7 +24,7 @@ bool SourceGroupFactoryModuleJava::supports(SourceGroupType type) const
return false; return false;
} }
std::shared_ptr<SourceGroup> SourceGroupFactoryModuleJava::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) std::shared_ptr<SourceGroup> SourceGroupFactoryModuleJava::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) const
{ {
std::shared_ptr<SourceGroup> sourceGroup; std::shared_ptr<SourceGroup> sourceGroup;
if (std::shared_ptr<SourceGroupSettingsJavaEmpty> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJavaEmpty>(settings)) if (std::shared_ptr<SourceGroupSettingsJavaEmpty> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJavaEmpty>(settings))
@@ -6,9 +6,8 @@
class SourceGroupFactoryModuleJava: public SourceGroupFactoryModule class SourceGroupFactoryModuleJava: public SourceGroupFactoryModule
{ {
public: public:
virtual ~SourceGroupFactoryModuleJava(); bool supports(SourceGroupType type) const override;
virtual bool supports(SourceGroupType type) const; std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) const override;
virtual std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings);
}; };
#endif // SOURCE_GROUP_FACTORY_MODULE_JAVA_H #endif // SOURCE_GROUP_FACTORY_MODULE_JAVA_H