]> granicus.if.org Git - clang/commitdiff
[Sema] Make typo correction slightly more efficient
authorFangrui Song <maskray@google.com>
Sun, 9 Sep 2018 17:20:03 +0000 (17:20 +0000)
committerFangrui Song <maskray@google.com>
Sun, 9 Sep 2018 17:20:03 +0000 (17:20 +0000)
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

lib/Sema/SemaLookup.cpp

index d0f133e064256b4764acd682449e7a3cb0f96745..8cf8dae886c9e450384bae0fd321eb0ee15c6420 100644 (file)
@@ -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();