From a37782dc0ccff51805538a6fe0810d121fc2c809 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 27 Nov 2018 09:19:22 -0800 Subject: [PATCH] Fix ComputeGuessScore and delete dead code Thanks to CXuesong --- src/project.cc | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/project.cc b/src/project.cc index 3f1df407..cc23c238 100644 --- a/src/project.cc +++ b/src/project.cc @@ -268,7 +268,7 @@ std::vector LoadFromDirectoryListing(ProjectConfig *config) { e.filename = file; e.args = GetCompilerArgumentForFile(file); if (e.args.empty()) - e.args.push_back("%clang"); // Add a Dummy. + e.args.push_back("%clang"); e.args.push_back(Intern(e.filename)); proc.Process(e); result.push_back(e); @@ -376,7 +376,7 @@ LoadEntriesFromDirectory(ProjectConfig *project, // argument guessing. int ComputeGuessScore(std::string_view a, std::string_view b) { // Increase score based on common prefix and suffix. Prefixes are prioritized. - if (a.size() < b.size()) + if (a.size() > b.size()) std::swap(a, b); size_t i = std::mismatch(a.begin(), a.end(), b.begin()).first - a.begin(); size_t j = std::mismatch(a.rbegin(), a.rend(), b.rbegin()).first - a.rbegin(); @@ -419,19 +419,6 @@ void Project::Load(const std::string &root) { } } -void Project::SetArgsForFile(const std::vector &args, - const std::string &path) { - std::lock_guard lock(mutex_); - for (auto &[root, folder] : root2folder) { - auto it = folder.path2entry_index.find(path); - if (it != folder.path2entry_index.end()) { - // The entry already exists in the project, just set the flags. - folder.entries[it->second].args = args; - return; - } - } -} - Project::Entry Project::FindEntry(const std::string &path, bool can_be_inferred) { std::lock_guard lock(mutex_);