From 0e9fb73463b82d5256025718cb722b4632ea3235 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Mon, 3 Sep 2018 16:51:48 +0200 Subject: [PATCH] logic: improved performance of querying filepaths from CDB * we don't need to get the complete compile commands for this * as a fallback, querying a single compile command for a file is fast, because it is stored in a map --- .../data/indexer/IndexerCommandCxxCdb.cpp | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp index 8dc35d97..19ed57f3 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp @@ -4,6 +4,7 @@ #include "clang/Tooling/JSONCompilationDatabase.h" #include "utility/logging/logging.h" #include "utility/messaging/type/MessageStatus.h" +#include "utility/OrderedCache.h" std::vector IndexerCommandCxxCdb::getSourceFilesFromCDB(const FilePath& compilationDatabasePath) { @@ -21,14 +22,21 @@ std::vector IndexerCommandCxxCdb::getSourceFilesFromCDB(const FilePath std::vector filePaths; if (cdb) { - for (const clang::tooling::CompileCommand& command : cdb->getAllCompileCommands()) + OrderedCache canonicalDirectoryPathCache([](const FilePath& path) { return path.getCanonical(); }); + + for (const std::string& fileString : cdb->getAllFiles()) { - FilePath path = FilePath(utility::decodeFromUtf8(command.Filename)).makeCanonical(); + FilePath path = FilePath(utility::decodeFromUtf8(fileString)); if (!path.isAbsolute()) { - path = FilePath(utility::decodeFromUtf8(command.Directory + '/' + command.Filename)).makeCanonical(); + std::vector commands = cdb->getCompileCommands(fileString); + if (!commands.empty()) + { + path = FilePath(utility::decodeFromUtf8(commands.front().Directory + '/' + commands.front().Filename)); + } } - filePaths.push_back(path); + + filePaths.push_back(canonicalDirectoryPathCache.getValue(path.getParentDirectory()).concatenate(path.fileName())); } } return filePaths; @@ -50,13 +58,13 @@ IndexerCommandCxxCdb::IndexerCommandCxxCdb( const std::vector& frameworkSearchPaths ) : IndexerCommandCxx( - sourceFilePath, - indexedPaths, - excludeFilters, - includeFilters, - workingDirectory, + sourceFilePath, + indexedPaths, + excludeFilters, + includeFilters, + workingDirectory, systemHeaderSearchPaths, - frameworkSearchPaths, + frameworkSearchPaths, compilerFlags) { }