r341763 - [Sema] Make typo correction slightly more efficient

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 9 10:20:03 PDT 2018


Author: maskray
Date: Sun Sep  9 10:20:03 2018
New Revision: 341763

URL: http://llvm.org/viewvc/llvm-project?rev=341763&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=341763&r1=341762&r2=341763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Sun Sep  9 10:20:03 2018
@@ -3998,9 +3998,9 @@ void TypoCorrectionConsumer::addName(Str
 
   // 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();




More information about the cfe-commits mailing list