summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-10-19 19:39:10 +0000
committerDouglas Gregor <dgregor@apple.com>2010-10-19 19:39:10 +0000
commit93910a5a59f3171cecec458b203127862d0cee2b (patch)
treeee72ce9a9cf84c8e726dfc2a2606bace3afd9fba
parentee8d15157adbababaf925aed754a812105f247d4 (diff)
downloadbcm5719-llvm-93910a5a59f3171cecec458b203127862d0cee2b.tar.gz
bcm5719-llvm-93910a5a59f3171cecec458b203127862d0cee2b.zip
Improve the performance of typo correction, by using a simple
computation to compute the lower bound of the edit distance, so that we can avoid computing the edit distance for names that will clearly be rejected later. Since edit distance is such an expensive algorithm (M x N), this leads to a 7.5x speedup when correcting NSstring -> NSString in the presence of a Cocoa PCH. llvm-svn: 116849
-rw-r--r--clang/lib/Sema/SemaLookup.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 6cd0207c800..de581fc6c60 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -2730,6 +2730,12 @@ void TypoCorrectionConsumer::FoundDecl(NamedDecl *ND, NamedDecl *Hiding,
}
void TypoCorrectionConsumer::FoundName(llvm::StringRef Name) {
+ // 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 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.
OpenPOWER on IntegriCloud