| Index: third_party/WebKit/Source/wtf/text/StringImpl.cpp
|
| diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.cpp b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
|
| index e7004b9244bd8d3feaf910f8135488ca4c93a090..b1b14798ee8d937110cc3a550066b33d833cba93 100644
|
| --- a/third_party/WebKit/Source/wtf/text/StringImpl.cpp
|
| +++ b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
|
| @@ -1246,15 +1246,26 @@ ALWAYS_INLINE static size_t findInternal(const SearchCharacterType* searchCharac
|
| // delta is the number of additional times to test; delta == 0 means test only once.
|
| unsigned delta = searchLength - matchLength;
|
|
|
| + // Find on a single character is very fast, so first do that to figure out
|
| + // where to start.
|
| + size_t start = WTF::find(searchCharacters, searchLength, matchCharacters[0]);
|
| + if (start == kNotFound || start > delta)
|
| + return kNotFound;
|
| +
|
| + // TODO(esprehn): Consider using Boyer-Moore-Horspool or a hybrid approach
|
| + // like v8/src/string-search.h, also investigate the badness factor used
|
| + // by v8 where they use single char find() repeatedly until they think
|
| + // it's too costly then switch to Boyer-Moore-Horspool.
|
| +
|
| unsigned searchHash = 0;
|
| unsigned matchHash = 0;
|
|
|
| for (unsigned i = 0; i < matchLength; ++i) {
|
| - searchHash += searchCharacters[i];
|
| + searchHash += searchCharacters[start + i];
|
| matchHash += matchCharacters[i];
|
| }
|
|
|
| - unsigned i = 0;
|
| + unsigned i = start;
|
| // keep looping until we match
|
| while (searchHash != matchHash || !equal(searchCharacters + i, matchCharacters, matchLength)) {
|
| if (i == delta)
|
|
|