[llvm-commits] [llvm] r82777 - /llvm/trunk/utils/FileCheck/FileCheck.cpp

Chris Lattner sabre at nondot.org
Fri Sep 25 10:09:13 PDT 2009


Author: lattner
Date: Fri Sep 25 12:09:12 2009
New Revision: 82777

URL: http://llvm.org/viewvc/llvm-project?rev=82777&view=rev
Log:
special case Patterns that are a single fixed string.  This is a microscopic
perf win and is needed for future changes.

Modified:
    llvm/trunk/utils/FileCheck/FileCheck.cpp

Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=82777&r1=82776&r2=82777&view=diff

==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Fri Sep 25 12:09:12 2009
@@ -75,6 +75,8 @@
   /// Chunks - The pattern chunks to match.  If the bool is false, it is a fixed
   /// string match, if it is true, it is a regex match.
   SmallVector<PatternChunk, 4> Chunks;
+  
+  StringRef FixedStr;
 public:
   
   Pattern() { }
@@ -101,6 +103,14 @@
     return true;
   }
   
+  // Check to see if this is a fixed string, or if it has regex pieces.
+  if (PatternStr.size() < 2 || PatternStr.find("{{") == StringRef::npos) {
+    FixedStr = PatternStr;
+    return false;
+  }
+  
+  // Otherwise, there is at least one regex piece.
+  
   // Scan the pattern to break it into regex and non-regex pieces.
   while (!PatternStr.empty()) {
     // Handle fixed string matches.
@@ -141,6 +151,12 @@
 /// returns the position that is matched or npos if there is no match.  If
 /// there is a match, the size of the matched string is returned in MatchLen.
 size_t Pattern::Match(StringRef Buffer, size_t &MatchLen) const {
+  // If this is a fixed string pattern, just match it now.
+  if (!FixedStr.empty()) {
+    MatchLen = FixedStr.size();
+    return Buffer.find(FixedStr);
+  }
+  
   size_t FirstMatch = StringRef::npos;
   MatchLen = 0;
   





More information about the llvm-commits mailing list