From: Fangrui Song Date: Sun, 9 Sep 2018 17:20:03 +0000 (+0000) Subject: [Sema] Make typo correction slightly more efficient X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51bf0d9b64c8a4a277eef2343456f9a14b38a0ef;p=clang [Sema] Make typo correction slightly more efficient edit_distance returns UpperBound+1 if the distance will exceed UpperBound. We can subtract 1 from UpperBound and change >= to > in the if condition. The threshold does not change but edit_distance will have more opportunity to bail out earlier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341763 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index d0f133e064..8cf8dae886 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3998,9 +3998,9 @@ void TypoCorrectionConsumer::addName(StringRef Name, NamedDecl *ND, // Compute an upper bound on the allowable edit distance, so that the // edit-distance algorithm can short-circuit. - unsigned UpperBound = (TypoStr.size() + 2) / 3 + 1; + unsigned UpperBound = (TypoStr.size() + 2) / 3; unsigned ED = TypoStr.edit_distance(Name, true, UpperBound); - if (ED >= UpperBound) return; + if (ED > UpperBound) return; TypoCorrection TC(&SemaRef.Context.Idents.get(Name), ND, NNS, ED); if (isKeyword) TC.makeKeyword();