logic: improved performance of code blocks indexed header detection
This commit is contained in:
@@ -73,6 +73,12 @@ namespace utility
|
||||
template<typename SourceType, typename TargetType>
|
||||
std::vector<TargetType> convert(const std::vector<SourceType>& sourceContainer);
|
||||
|
||||
template<typename SourceType, typename TargetType>
|
||||
std::set<TargetType> convert(const std::set<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion);
|
||||
|
||||
template<typename SourceType, typename TargetType>
|
||||
std::set<TargetType> convert(const std::set<SourceType>& sourceContainer);
|
||||
|
||||
template<typename T>
|
||||
std::vector<std::string> toStrings(const std::vector<T>& d);
|
||||
template<>
|
||||
@@ -259,7 +265,8 @@ template<typename SourceType, typename TargetType>
|
||||
std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion)
|
||||
{
|
||||
std::vector<TargetType> targetContainer;
|
||||
for (const SourceType& sourceElement: sourceContainer)
|
||||
targetContainer.reserve(sourceContainer.size());
|
||||
for (const SourceType& sourceElement : sourceContainer)
|
||||
{
|
||||
targetContainer.push_back(conversion(sourceElement));
|
||||
}
|
||||
@@ -270,6 +277,7 @@ template<typename SourceType, typename TargetType>
|
||||
std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceContainer)
|
||||
{
|
||||
std::vector<TargetType> targetContainer;
|
||||
targetContainer.reserve(sourceContainer.size());
|
||||
for (const SourceType& sourceElement : sourceContainer)
|
||||
{
|
||||
targetContainer.push_back(TargetType(sourceElement));
|
||||
@@ -277,6 +285,28 @@ std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceCo
|
||||
return targetContainer;
|
||||
}
|
||||
|
||||
template<typename SourceType, typename TargetType>
|
||||
std::set<TargetType> utility::convert(const std::set<SourceType>& sourceContainer, std::function<TargetType(const SourceType&)> conversion)
|
||||
{
|
||||
std::set<TargetType> targetContainer;
|
||||
for (const SourceType& sourceElement : sourceContainer)
|
||||
{
|
||||
targetContainer.insert(conversion(sourceElement));
|
||||
}
|
||||
return targetContainer;
|
||||
}
|
||||
|
||||
template<typename SourceType, typename TargetType>
|
||||
std::set<TargetType> utility::convert(const std::set<SourceType>& sourceContainer)
|
||||
{
|
||||
std::set<TargetType> targetContainer;
|
||||
for (const SourceType& sourceElement : sourceContainer)
|
||||
{
|
||||
targetContainer.insert(TargetType(sourceElement));
|
||||
}
|
||||
return targetContainer;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<std::string> utility::toStrings(const std::vector<T>& d)
|
||||
{
|
||||
|
||||
@@ -129,7 +129,17 @@ namespace Codeblocks
|
||||
std::shared_ptr<const SourceGroupSettingsWithSourceExtensions> sourceGroupSettings
|
||||
) const
|
||||
{
|
||||
const std::set<std::wstring> sourceExtensions = utility::toSet(sourceGroupSettings->getSourceExtensions());
|
||||
return utility::convert<FilePath, FilePath>(getAllSourceFilePaths(sourceGroupSettings), [](const FilePath& path) { return path.getCanonical(); });
|
||||
}
|
||||
|
||||
std::set<FilePath> Project::getAllSourceFilePaths(
|
||||
std::shared_ptr<const SourceGroupSettingsWithSourceExtensions> sourceGroupSettings
|
||||
) const
|
||||
{
|
||||
const std::set<std::wstring> sourceExtensions = utility::toSet(utility::convert<std::wstring, std::wstring>(
|
||||
sourceGroupSettings->getSourceExtensions(),
|
||||
[](const std::wstring& e) { return utility::toLowerCase(e); }
|
||||
));
|
||||
|
||||
std::set<FilePath> filePaths;
|
||||
for (std::shared_ptr<const Unit> unit : m_units)
|
||||
@@ -139,7 +149,7 @@ namespace Codeblocks
|
||||
FilePath filePath(unit->getFilename());
|
||||
if (sourceExtensions.find(filePath.getLowerCase().extension()) != sourceExtensions.end())
|
||||
{
|
||||
filePaths.insert(filePath.makeCanonical());
|
||||
filePaths.insert(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,16 +158,33 @@ namespace Codeblocks
|
||||
|
||||
std::set<FilePath> Project::getAllCxxHeaderSearchPathsCanonical() const
|
||||
{
|
||||
std::set<std::wstring> usedTargetNames;
|
||||
for (std::shared_ptr<const Unit> unit : m_units)
|
||||
{
|
||||
if (unit && unit->getCompile())
|
||||
{
|
||||
utility::append(usedTargetNames, unit->getTargetNames());
|
||||
}
|
||||
}
|
||||
|
||||
OrderedCache<FilePath, FilePath> canonicalDirectoryPathCache([](const FilePath& path) {
|
||||
return path.getCanonical();
|
||||
});
|
||||
|
||||
std::set<FilePath> paths;
|
||||
for (std::shared_ptr<const Target> target : m_targets)
|
||||
{
|
||||
if (target)
|
||||
if (target && usedTargetNames.find(target->getTitle()) != usedTargetNames.end())
|
||||
{
|
||||
if (std::shared_ptr<const Compiler> compiler = target->getCompiler())
|
||||
{
|
||||
for (const std::wstring& directory : compiler->getDirectories())
|
||||
{
|
||||
paths.insert(FilePath(directory).makeCanonical());
|
||||
FilePath path(directory);
|
||||
if (path.isAbsolute())
|
||||
{
|
||||
paths.insert(canonicalDirectoryPathCache.getValue(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ namespace Codeblocks
|
||||
std::set<FilePath> getAllSourceFilePathsCanonical(
|
||||
std::shared_ptr<const SourceGroupSettingsWithSourceExtensions> sourceGroupSettings
|
||||
) const;
|
||||
std::set<FilePath> getAllSourceFilePaths(
|
||||
std::shared_ptr<const SourceGroupSettingsWithSourceExtensions> sourceGroupSettings
|
||||
) const;
|
||||
std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const;
|
||||
|
||||
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
|
||||
|
||||
@@ -312,9 +312,13 @@ std::vector<FilePath> QtProjectWizzardContentIndexedHeaderPaths::getIndexedPaths
|
||||
{
|
||||
if (std::shared_ptr<Codeblocks::Project> codeblocksProject = Codeblocks::Project::load(codeblocksProjectPath))
|
||||
{
|
||||
for (const FilePath& path : codeblocksProject->getAllSourceFilePathsCanonical(settings))
|
||||
OrderedCache<FilePath, FilePath> canonicalDirectoryPathCache([](const FilePath& path) {
|
||||
return path.getCanonical();
|
||||
});
|
||||
|
||||
for (const FilePath& path : codeblocksProject->getAllSourceFilePaths(settings))
|
||||
{
|
||||
indexedHeaderPaths.insert(path.getCanonical().getParentDirectory());
|
||||
indexedHeaderPaths.insert(canonicalDirectoryPathCache.getValue(path.getParentDirectory()));
|
||||
}
|
||||
utility::append(indexedHeaderPaths, codeblocksProject->getAllCxxHeaderSearchPathsCanonical());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user