FileCheck: When looking for "possible matches", only compare against the prefix
authorDaniel Dunbar <daniel@zuster.org>
Sat, 30 Jan 2010 00:24:06 +0000 (00:24 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 30 Jan 2010 00:24:06 +0000 (00:24 +0000)
line. Turns out edit_distance can be slow if the string we are scanning for
happens to be quite large.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94860 91177308-0d34-0410-b5e6-96231b3b80d8

utils/FileCheck/FileCheck.cpp

index 9619f945aace711248657df63374d2e2f3db7901..3c4742cc36fbed0cc26619ae93707cacf782fccc 100644 (file)
@@ -340,7 +340,10 @@ unsigned Pattern::ComputeMatchDistance(StringRef Buffer,
   if (ExampleString.empty())
     ExampleString = RegExStr;
 
-  return Buffer.substr(0, ExampleString.size()).edit_distance(ExampleString);
+  // Only compare up to the first line in the buffer, or the string size.
+  StringRef BufferPrefix = Buffer.substr(0, ExampleString.size());
+  BufferPrefix = BufferPrefix.split('\n').first;
+  return BufferPrefix.edit_distance(ExampleString);
 }
 
 void Pattern::PrintFailureInfo(const SourceMgr &SM, StringRef Buffer,