A bit more work on making a faster compile_commands.json loader

This commit is contained in:
Jacob Dufault 2017-05-18 18:14:53 -07:00
parent 1d6477c3e9
commit cf45c91bcd
3 changed files with 25 additions and 2 deletions

View File

@ -171,8 +171,12 @@ std::vector<Project::Entry> LoadFromCompileCommandsJson(const std::vector<std::s
std::vector<Project::Entry> result; std::vector<Project::Entry> result;
result.reserve(entries.size()); result.reserve(entries.size());
for (const auto& entry : entries) for (auto& entry : entries) {
if (entry.args.empty() && !entry.command.empty())
entry.args = SplitString(entry.command, " ");
result.push_back(GetCompilationEntryFromCompileCommandEntry(extra_flags, entry)); result.push_back(GetCompilationEntryFromCompileCommandEntry(extra_flags, entry));
}
return result; return result;
} }
@ -211,7 +215,7 @@ std::vector<Project::Entry> LoadFromDirectoryListing(const std::vector<std::stri
std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(const std::vector<std::string>& extra_flags, const std::string& project_directory) { std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(const std::vector<std::string>& extra_flags, const std::string& project_directory) {
// TODO: Figure out if this function or the clang one is faster. // TODO: Figure out if this function or the clang one is faster.
//return LoadFromCompileCommandsJson(project_directory); //return LoadFromCompileCommandsJson(extra_flags, project_directory);
std::cerr << "Trying to load compile_commands.json" << std::endl; std::cerr << "Trying to load compile_commands.json" << std::endl;
CXCompilationDatabase_Error cx_db_load_error; CXCompilationDatabase_Error cx_db_load_error;

View File

@ -66,6 +66,23 @@ std::string ReplaceAll(const std::string& source, const std::string& from, const
return result; return result;
} }
std::vector<std::string> SplitString(const std::string& str, const std::string& delimiter) {
// http://stackoverflow.com/a/13172514
std::vector<std::string> strings;
std::string::size_type pos = 0;
std::string::size_type prev = 0;
while ((pos = str.find(delimiter, prev)) != std::string::npos) {
strings.push_back(str.substr(prev, pos - prev));
prev = pos + 1;
}
// To get the last substring (or only, if delimiter is not found)
strings.push_back(str.substr(prev));
return strings;
}
static std::vector<std::string> GetFilesInFolderHelper(std::string folder, bool recursive, std::string output_prefix) { static std::vector<std::string> GetFilesInFolderHelper(std::string folder, bool recursive, std::string output_prefix) {
std::vector<std::string> result; std::vector<std::string> result;

View File

@ -18,6 +18,8 @@ bool StartsWith(const std::string& value, const std::string& start);
bool EndsWith(const std::string& value, const std::string& ending); bool EndsWith(const std::string& value, const std::string& ending);
std::string ReplaceAll(const std::string& source, const std::string& from, const std::string& to); std::string ReplaceAll(const std::string& source, const std::string& from, const std::string& to);
std::vector<std::string> SplitString(const std::string& str, const std::string& delimiter);
inline bool StartsWithAny(const std::vector<std::string>& values, const std::string& start) { inline bool StartsWithAny(const std::vector<std::string>& values, const std::string& start) {
return std::any_of(std::begin(values), std::end(values), [&start](const std::string& value) { return std::any_of(std::begin(values), std::end(values), [&start](const std::string& value) {
return StartsWith(value, start); return StartsWith(value, start);