summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-10-15 10:08:31 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-10-15 10:08:31 +0000
commit6e6a558ebce556476d8fd659b419a2760f2ab154 (patch)
tree0331aaeaa342b5fd9f0adf98895d3d91e2182f4f /unittests
parente9b58d0aac4e89b53a4be0e6f289b66649e1512b (diff)
downloadllvm-6e6a558ebce556476d8fd659b419a2760f2ab154.tar.gz
llvm-6e6a558ebce556476d8fd659b419a2760f2ab154.tar.bz2
llvm-6e6a558ebce556476d8fd659b419a2760f2ab154.tar.xz
Add a bad char heuristic to StringRef::find.
Based on Horspool's simplified version of Boyer-Moore. We use a constant-sized table of uint8_ts to keep cache thrashing low, needles bigger than 255 bytes are uncommon anyways. The worst case is still O(n*m) but we do a lot better on the average case now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142061 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/StringRefTest.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp
index 8364eac827..d91084381e 100644
--- a/unittests/ADT/StringRefTest.cpp
+++ b/unittests/ADT/StringRefTest.cpp
@@ -245,6 +245,12 @@ TEST(StringRefTest, Find) {
EXPECT_EQ(StringRef::npos, Str.find("zz"));
EXPECT_EQ(2U, Str.find("ll", 2));
EXPECT_EQ(StringRef::npos, Str.find("ll", 3));
+ EXPECT_EQ(0U, Str.find(""));
+ StringRef LongStr("hellx xello hell ello world foo bar hello");
+ EXPECT_EQ(36U, LongStr.find("hello"));
+ EXPECT_EQ(28U, LongStr.find("foo"));
+ EXPECT_EQ(12U, LongStr.find("hell", 2));
+ EXPECT_EQ(0U, LongStr.find(""));
EXPECT_EQ(3U, Str.rfind('l'));
EXPECT_EQ(StringRef::npos, Str.rfind('z'));