Fix ComputeGuessScore and delete dead code

Thanks to CXuesong
This commit is contained in:
Fangrui Song 2018-11-27 09:19:22 -08:00
parent 65d856cf8a
commit c6c234725a

View File

@ -256,7 +256,7 @@ std::vector<Project::Entry> 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);
@ -364,7 +364,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();
@ -407,19 +407,6 @@ void Project::Load(const std::string &root) {
}
}
void Project::SetArgsForFile(const std::vector<const char *> &args,
const std::string &path) {
std::lock_guard<std::mutex> 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<std::mutex> lock(mutex_);