logic: improved performance of "setting up indexers" step for CDB SourceGroups
* improved performance of generating IndexerCommandProviders of CDB SourceGroups
This commit is contained in:
@@ -145,13 +145,13 @@ std::vector<std::vector<T>> utility::splitToEqualySizedParts(const std::vector<T
|
||||
std::vector<std::vector<T>> parts;
|
||||
for (size_t i = 0; i < partCount; i++)
|
||||
{
|
||||
parts.push_back(std::vector<T>());
|
||||
parts.emplace_back(std::vector<T>());
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (const T& value : values)
|
||||
{
|
||||
parts[i % partCount].push_back(value);
|
||||
parts[i % partCount].emplace_back(value);
|
||||
++i;
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ std::set<T> utility::toSet(const std::vector<T>& v)
|
||||
template<typename T>
|
||||
void utility::fillVectorWithElements(std::vector<T>& v, const T& arg)
|
||||
{
|
||||
v.push_back(arg);
|
||||
v.emplace_back(arg);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
@@ -269,7 +269,7 @@ std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceCo
|
||||
targetContainer.reserve(sourceContainer.size());
|
||||
for (const SourceType& sourceElement : sourceContainer)
|
||||
{
|
||||
targetContainer.push_back(conversion(sourceElement));
|
||||
targetContainer.emplace_back(conversion(sourceElement));
|
||||
}
|
||||
return targetContainer;
|
||||
}
|
||||
@@ -281,7 +281,7 @@ std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceCo
|
||||
targetContainer.reserve(sourceContainer.size());
|
||||
for (const SourceType& sourceElement : sourceContainer)
|
||||
{
|
||||
targetContainer.push_back(TargetType(sourceElement));
|
||||
targetContainer.emplace_back(TargetType(sourceElement));
|
||||
}
|
||||
return targetContainer;
|
||||
}
|
||||
|
||||
@@ -12,51 +12,57 @@ void CxxIndexerCommandProvider::addCommand(const std::shared_ptr<IndexerCommandC
|
||||
{
|
||||
std::shared_ptr<CommandRepresentation> representation = std::make_shared<CommandRepresentation>();
|
||||
|
||||
for (const FilePath& indexedPath : command->getIndexedPaths())
|
||||
{
|
||||
std::map<FilePath, Id>::const_iterator it = m_indexedPathsToIds.find(indexedPath);
|
||||
if (it != m_indexedPathsToIds.end())
|
||||
for (const FilePath& indexedPath : command->getIndexedPaths())
|
||||
{
|
||||
representation->m_indexedPathIds.insert(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_indexedPathsToIds[indexedPath] = id;
|
||||
m_idsToIndexedPaths[id] = indexedPath;
|
||||
representation->m_indexedPathIds.insert(id);
|
||||
std::map<FilePath, Id>::const_iterator it = m_indexedPathsToIds.find(indexedPath);
|
||||
if (it != m_indexedPathsToIds.end())
|
||||
{
|
||||
representation->m_indexedPathIds.emplace(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_indexedPathsToIds[indexedPath] = id;
|
||||
m_idsToIndexedPaths[id] = indexedPath;
|
||||
representation->m_indexedPathIds.emplace(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const FilePathFilter& excludeFilter : command->getExcludeFilters())
|
||||
{
|
||||
std::map<std::wstring, Id>::const_iterator it = m_excludeFiltersToIds.find(excludeFilter.wstr());
|
||||
if (it != m_excludeFiltersToIds.end())
|
||||
for (const FilePathFilter& excludeFilter : command->getExcludeFilters())
|
||||
{
|
||||
representation->m_excludeFilterIds.insert(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_excludeFiltersToIds[excludeFilter.wstr()] = id;
|
||||
m_idsToExcludeFilters[id] = excludeFilter.wstr();
|
||||
representation->m_excludeFilterIds.insert(id);
|
||||
std::map<std::wstring, Id>::const_iterator it = m_excludeFiltersToIds.find(excludeFilter.wstr());
|
||||
if (it != m_excludeFiltersToIds.end())
|
||||
{
|
||||
representation->m_excludeFilterIds.emplace(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_excludeFiltersToIds[excludeFilter.wstr()] = id;
|
||||
m_idsToExcludeFilters[id] = excludeFilter.wstr();
|
||||
representation->m_excludeFilterIds.emplace(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const FilePathFilter& includeFilter : command->getIncludeFilters())
|
||||
{
|
||||
std::map<std::wstring, Id>::const_iterator it = m_includeFiltersToIds.find(includeFilter.wstr());
|
||||
if (it != m_includeFiltersToIds.end())
|
||||
for (const FilePathFilter& includeFilter : command->getIncludeFilters())
|
||||
{
|
||||
representation->m_includeFilterIds.insert(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_includeFiltersToIds[includeFilter.wstr()] = id;
|
||||
m_idsToIncludeFilters[id] = includeFilter.wstr();
|
||||
representation->m_includeFilterIds.insert(id);
|
||||
std::map<std::wstring, Id>::const_iterator it = m_includeFiltersToIds.find(includeFilter.wstr());
|
||||
if (it != m_includeFiltersToIds.end())
|
||||
{
|
||||
representation->m_includeFilterIds.emplace(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_includeFiltersToIds[includeFilter.wstr()] = id;
|
||||
m_idsToIncludeFilters[id] = includeFilter.wstr();
|
||||
representation->m_includeFilterIds.emplace(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,51 +82,63 @@ void CxxIndexerCommandProvider::addCommand(const std::shared_ptr<IndexerCommandC
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::wstring& compilerFlag : command->getCompilerFlags())
|
||||
{
|
||||
std::map<std::wstring, Id>::const_iterator it = m_compilerFlagsToIds.find(compilerFlag);
|
||||
if (it != m_compilerFlagsToIds.end())
|
||||
const std::vector<std::wstring>& compilerFlags = command->getCompilerFlags();
|
||||
representation->m_compilerFlagIds.reserve(compilerFlags.size());
|
||||
for (const std::wstring& compilerFlag : compilerFlags)
|
||||
{
|
||||
representation->m_compilerFlagIds.push_back(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_compilerFlagsToIds[compilerFlag] = id;
|
||||
m_idsToCompilerFlags[id] = compilerFlag;
|
||||
representation->m_compilerFlagIds.push_back(id);
|
||||
std::unordered_map<std::wstring, Id>::const_iterator it = m_compilerFlagsToIds.find(compilerFlag);
|
||||
if (it != m_compilerFlagsToIds.end())
|
||||
{
|
||||
representation->m_compilerFlagIds.emplace_back(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_compilerFlagsToIds.emplace(compilerFlag, id);
|
||||
m_idsToCompilerFlags.emplace(id, compilerFlag);
|
||||
representation->m_compilerFlagIds.emplace_back(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const FilePath& systemHeaderSearchPath : command->getSystemHeaderSearchPaths())
|
||||
{
|
||||
std::map<FilePath, Id>::const_iterator it = m_systemHeaderSearchPathsToIds.find(systemHeaderSearchPath);
|
||||
if (it != m_systemHeaderSearchPathsToIds.end())
|
||||
const std::vector<FilePath>& systemHeaderSearchPaths = command->getSystemHeaderSearchPaths();
|
||||
representation->m_systemHeaderSearchPathIds.reserve(systemHeaderSearchPaths.size());
|
||||
for (const FilePath& systemHeaderSearchPath : systemHeaderSearchPaths)
|
||||
{
|
||||
representation->m_systemHeaderSearchPathIds.push_back(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_systemHeaderSearchPathsToIds[systemHeaderSearchPath] = id;
|
||||
m_idsToSystemHeaderSearchPaths[id] = systemHeaderSearchPath;
|
||||
representation->m_systemHeaderSearchPathIds.push_back(id);
|
||||
std::map<FilePath, Id>::const_iterator it = m_systemHeaderSearchPathsToIds.find(systemHeaderSearchPath);
|
||||
if (it != m_systemHeaderSearchPathsToIds.end())
|
||||
{
|
||||
representation->m_systemHeaderSearchPathIds.emplace_back(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_systemHeaderSearchPathsToIds[systemHeaderSearchPath] = id;
|
||||
m_idsToSystemHeaderSearchPaths[id] = systemHeaderSearchPath;
|
||||
representation->m_systemHeaderSearchPathIds.emplace_back(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const FilePath& frameworkSearchPath : command->getFrameworkSearchPaths())
|
||||
{
|
||||
std::map<FilePath, Id>::const_iterator it = m_frameworkSearchPathsToIds.find(frameworkSearchPath);
|
||||
if (it != m_frameworkSearchPathsToIds.end())
|
||||
const std::vector<FilePath>& frameworkSearchPaths = command->getFrameworkSearchPaths();
|
||||
representation->m_frameworkSearchPathIds.reserve(frameworkSearchPaths.size());
|
||||
for (const FilePath& frameworkSearchPath : frameworkSearchPaths)
|
||||
{
|
||||
representation->m_frameworkSearchPathIds.push_back(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_frameworkSearchPathsToIds[frameworkSearchPath] = id;
|
||||
m_idsToFrameworkSearchPaths[id] = frameworkSearchPath;
|
||||
representation->m_frameworkSearchPathIds.push_back(id);
|
||||
std::map<FilePath, Id>::const_iterator it = m_frameworkSearchPathsToIds.find(frameworkSearchPath);
|
||||
if (it != m_frameworkSearchPathsToIds.end())
|
||||
{
|
||||
representation->m_frameworkSearchPathIds.emplace_back(it->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Id id = getId();
|
||||
m_frameworkSearchPathsToIds[frameworkSearchPath] = id;
|
||||
m_idsToFrameworkSearchPaths[id] = frameworkSearchPath;
|
||||
representation->m_frameworkSearchPathIds.emplace_back(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "data/indexer/IndexerCommandProvider.h"
|
||||
#include "utility/types.h"
|
||||
@@ -54,7 +55,7 @@ private:
|
||||
std::map<Id, FilePath> m_idsToFrameworkSearchPaths;
|
||||
std::map<FilePath, Id> m_frameworkSearchPathsToIds;
|
||||
std::map<Id, std::wstring> m_idsToCompilerFlags;
|
||||
std::map<std::wstring, Id> m_compilerFlagsToIds;
|
||||
std::unordered_map<std::wstring, Id> m_compilerFlagsToIds;
|
||||
};
|
||||
|
||||
#endif // CXX_INDEXER_COMMAND_PROVIDER_H
|
||||
|
||||
@@ -102,9 +102,8 @@ std::shared_ptr<IndexerCommandProvider> SourceGroupCxxCdb::getIndexerCommandProv
|
||||
const std::set<FilePathFilter> excludeFilters = utility::toSet(m_settings->getExcludeFiltersExpandedAndAbsolute());
|
||||
|
||||
std::string error;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb =
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase>(
|
||||
clang::tooling::JSONCompilationDatabase::loadFromFile(utility::encodeToUtf8(cdbPath.wstr()),
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>(
|
||||
clang::tooling::JSONCompilationDatabase::loadFromFile(utility::encodeToUtf8(cdbPath.wstr()),
|
||||
error,
|
||||
clang::tooling::JSONCommandLineSyntax::AutoDetect
|
||||
)
|
||||
@@ -118,31 +117,38 @@ std::shared_ptr<IndexerCommandProvider> SourceGroupCxxCdb::getIndexerCommandProv
|
||||
}
|
||||
|
||||
const std::set<FilePath>& sourceFilePaths = getAllSourceFilePaths();
|
||||
|
||||
for (const clang::tooling::CompileCommand& command: cdb->getAllCompileCommands())
|
||||
if (cdb)
|
||||
{
|
||||
FilePath sourcePath = FilePath(utility::decodeFromUtf8(command.Filename)).makeCanonical();
|
||||
if (!sourcePath.isAbsolute())
|
||||
for (const clang::tooling::CompileCommand& command: cdb->getAllCompileCommands())
|
||||
{
|
||||
sourcePath = FilePath(utility::decodeFromUtf8(command.Directory + '/' + command.Filename)).makeCanonical();
|
||||
}
|
||||
FilePath sourcePath = FilePath(utility::decodeFromUtf8(command.Filename)).makeCanonical();
|
||||
if (!sourcePath.isAbsolute())
|
||||
{
|
||||
sourcePath = FilePath(utility::decodeFromUtf8(command.Directory + '/' + command.Filename)).makeCanonical();
|
||||
}
|
||||
|
||||
if (filesToIndex.find(sourcePath) != filesToIndex.end() &&
|
||||
sourceFilePaths.find(sourcePath) != sourceFilePaths.end())
|
||||
{
|
||||
provider->addCommand(std::make_shared<IndexerCommandCxx>(
|
||||
sourcePath,
|
||||
utility::concat(indexedHeaderPaths, { sourcePath }),
|
||||
excludeFilters,
|
||||
std::set<FilePathFilter>(),
|
||||
FilePath(utility::decodeFromUtf8(command.Directory)),
|
||||
systemHeaderSearchPaths,
|
||||
frameworkSearchPaths,
|
||||
utility::concat(
|
||||
utility::convert<std::string, std::wstring>(command.CommandLine, [](const std::string& arg) { return utility::decodeFromUtf8(arg); }),
|
||||
compilerFlags
|
||||
)
|
||||
));
|
||||
if (filesToIndex.find(sourcePath) != filesToIndex.end() &&
|
||||
sourceFilePaths.find(sourcePath) != sourceFilePaths.end())
|
||||
{
|
||||
std::vector<std::wstring> mergedCompilerFlags;
|
||||
mergedCompilerFlags.reserve(compilerFlags.size() + command.CommandLine.size());
|
||||
for (const std::string& arg : command.CommandLine)
|
||||
{
|
||||
mergedCompilerFlags.emplace_back(utility::decodeFromUtf8(arg));
|
||||
}
|
||||
mergedCompilerFlags.insert(mergedCompilerFlags.end(), compilerFlags.begin(), compilerFlags.end());
|
||||
|
||||
provider->addCommand(std::make_shared<IndexerCommandCxx>(
|
||||
sourcePath,
|
||||
utility::concat(indexedHeaderPaths, { sourcePath }),
|
||||
excludeFilters,
|
||||
std::set<FilePathFilter>(),
|
||||
FilePath(utility::decodeFromUtf8(command.Directory)),
|
||||
systemHeaderSearchPaths,
|
||||
frameworkSearchPaths,
|
||||
mergedCompilerFlags
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user