summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Option/OptTable.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-05-01 14:46:17 +0000
committerNico Weber <nicolasweber@gmx.de>2019-05-01 14:46:17 +0000
commitf68e0f79c77544bb823478730c631f5417601f14 (patch)
tree571752f83484224bd93331b72286969ba2fb5b21 /llvm/lib/Option/OptTable.cpp
parentd8f856d26549d15fd229ce372ee436b42fff628d (diff)
downloadbcm5719-llvm-f68e0f79c77544bb823478730c631f5417601f14.tar.gz
bcm5719-llvm-f68e0f79c77544bb823478730c631f5417601f14.zip
Fix OptTable::findNearest() adding delimiter for free
Prior to this, OptTable::findNearest() thought that the input `--foo` had an editing distance of 0 from an existing flag `--foo=`, which made it suggest flags with delimiters more often than flags without one. After this, it correctly assigns this case an editing distance of 1. Differential Revision: https://reviews.llvm.org/D61373 llvm-svn: 359685
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r--llvm/lib/Option/OptTable.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index 944de9f417e..47c5f80c7d7 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -280,23 +280,22 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
// Now check if the candidate ends with a character commonly used when
// delimiting an option from its value, such as '=' or ':'. If it does,
// attempt to split the given option based on that delimiter.
- std::string Delimiter = "";
- char Last = CandidateName.back();
- if (Last == '=' || Last == ':')
- Delimiter = std::string(1, Last);
-
StringRef LHS, RHS;
- if (Delimiter.empty())
- LHS = Option;
- else
+ char Last = CandidateName.back();
+ bool CandidateHasDelimiter = Last == '=' || Last == ':';
+ std::string NormalizedName = Option;
+ if (CandidateHasDelimiter) {
std::tie(LHS, RHS) = Option.split(Last);
+ NormalizedName = LHS;
+ if (Option.find(Last) == LHS.size())
+ NormalizedName += Last;
+ }
// Consider each possible prefix for each candidate to find the most
// appropriate one. For example, if a user asks for "--helm", suggest
// "--help" over "-help".
for (int P = 0;
const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) {
- std::string NormalizedName = (LHS + Delimiter).str();
std::string Candidate = (CandidatePrefix + CandidateName).str();
StringRef CandidateRef = Candidate;
unsigned Distance =
OpenPOWER on IntegriCloud