[cfe-commits] r116868 - /cfe/trunk/lib/Sema/SemaLookup.cpp

Douglas Gregor dgregor at apple.com
Tue Oct 19 15:14:33 PDT 2010


Author: dgregor
Date: Tue Oct 19 17:14:33 2010
New Revision: 116868

URL: http://llvm.org/viewvc/llvm-project?rev=116868&view=rev
Log:
Provide an upper bound to the edit-distance algorithm when performing
typo correction, to allow early exits.

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=116868&r1=116867&r2=116868&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Oct 19 17:14:33 2010
@@ -2730,16 +2730,22 @@
 }
 
 void TypoCorrectionConsumer::FoundName(llvm::StringRef Name) {
+  using namespace std;
+  
   // Use a simple length-based heuristic to determine the minimum possible
   // edit distance. If the minimum isn't good enough, bail out early.
   unsigned MinED = abs((int)Name.size() - (int)Typo.size());
   if (MinED > BestEditDistance || (MinED && Typo.size() / MinED < 3))
     return;
   
+  // Compute an upper bound on the allowable edit distance, so that the
+  // edit-distance algorithm can short-circuit.
+  unsigned UpperBound = min(unsigned((Typo.size() + 2) / 3), BestEditDistance);
+  
   // Compute the edit distance between the typo and the name of this
   // entity. If this edit distance is not worse than the best edit
   // distance we've seen so far, add it to the list of results.
-  unsigned ED = Typo.edit_distance(Name);
+  unsigned ED = Typo.edit_distance(Name, true, UpperBound);
   if (ED == 0)
     return;
   





More information about the cfe-commits mailing list