diff options
author | Fangrui Song <maskray@google.com> | 2018-09-09 17:20:03 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2018-09-09 17:20:03 +0000 |
commit | 51bf0d9b64c8a4a277eef2343456f9a14b38a0ef (patch) | |
tree | eb8c063410cbd4c8d130680ee6c6ddb3b8cd91ed /lib/Sema/SemaLookup.cpp | |
parent | a2f63564c9917cc72d6cb557db119e6390149e41 (diff) |
[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
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
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(); |