Skip to content

Commit 61b3bff

Browse files
committed
[NFC] Reduce duplication/special cases in GSB typo correction.
1 parent a4521c6 commit 61b3bff

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,7 +2824,7 @@ static Identifier typoCorrectNestedType(
28242824
// Look through all of the associated types of all of the protocols
28252825
// to which the parent conforms.
28262826
llvm::SmallVector<Identifier, 2> bestMatches;
2827-
unsigned bestEditDistance = 0;
2827+
unsigned bestEditDistance = UINT_MAX;
28282828
unsigned maxScore = (name.size() + 1) / 3;
28292829
for (auto proto : pa->getParent()->getConformsTo()) {
28302830
for (auto member : getProtocolMembers(proto)) {
@@ -2836,16 +2836,12 @@ static Identifier typoCorrectNestedType(
28362836
/*AllowReplacements=*/true,
28372837
maxScore);
28382838
assert(dist > 0 && "nested type should have matched associated type");
2839-
if (bestEditDistance == 0 || dist == bestEditDistance) {
2840-
bestEditDistance = dist;
2841-
maxScore = bestEditDistance;
2842-
bestMatches.push_back(assocType->getName());
2843-
} else if (dist < bestEditDistance) {
2844-
bestEditDistance = dist;
2845-
maxScore = bestEditDistance;
2839+
if (dist < bestEditDistance) {
2840+
maxScore = bestEditDistance = dist;
28462841
bestMatches.clear();
2847-
bestMatches.push_back(assocType->getName());
28482842
}
2843+
if (dist == bestEditDistance)
2844+
bestMatches.push_back(assocType->getName());
28492845
}
28502846
}
28512847

0 commit comments

Comments
 (0)