summaryrefslogtreecommitdiff
path: root/utils/FileCheck
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-09-25 17:09:12 +0000
committerChris Lattner <sabre@nondot.org>2009-09-25 17:09:12 +0000
commit2702e6aa53f603b20c3e46364bc1756788bd291a (patch)
tree8b362e180cd579e64d7c5dc8c8a3346840d0614e /utils/FileCheck
parent9f8380b42532c10cab5eb8616f962e10828e765f (diff)
downloadllvm-2702e6aa53f603b20c3e46364bc1756788bd291a.tar.gz
llvm-2702e6aa53f603b20c3e46364bc1756788bd291a.tar.bz2
llvm-2702e6aa53f603b20c3e46364bc1756788bd291a.tar.xz
special case Patterns that are a single fixed string. This is a microscopic
perf win and is needed for future changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82777 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/FileCheck')
-rw-r--r--utils/FileCheck/FileCheck.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp
index 1f79b92e9d..061d321b90 100644
--- a/utils/FileCheck/FileCheck.cpp
+++ b/utils/FileCheck/FileCheck.cpp
@@ -75,6 +75,8 @@ class Pattern {
/// 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 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
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 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
/// 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;