return os;
}
-namespace detail {
-
-size_t qfind_first_byte_of_memchr(const StringPiece haystack,
- const StringPiece needles) {
- size_t best = haystack.size();
- for (char needle: needles) {
- const void* ptr = memchr(haystack.data(), needle, best);
- if (ptr) {
- auto found = static_cast<const char*>(ptr) - haystack.data();
- best = std::min<size_t>(best, found);
- }
- }
- if (best == haystack.size()) {
- return StringPiece::npos;
- }
- return best;
-}
-
-} // namespace detail
-
namespace {
// It's okay if pages are bigger than this (as powers of two), but they should
DCHECK(!haystack.empty());
DCHECK(!needles.empty());
DCHECK_LE(needles.size(), 16);
- // benchmarking shows that memchr beats out SSE for small needle-sets
- // with large haystacks.
if ((needles.size() <= 2 && haystack.size() >= 256) ||
// must bail if we can't even SSE-load a single segment of haystack
(haystack.size() < 16 &&
PAGE_FOR(haystack.end() - 1) != PAGE_FOR(haystack.data() + 15)) ||
// can't load needles into SSE register if it could cross page boundary
PAGE_FOR(needles.end() - 1) != PAGE_FOR(needles.data() + 15)) {
- return detail::qfind_first_byte_of_memchr(haystack, needles);
+ return detail::qfind_first_byte_of_nosse(haystack, needles);
}
auto arr2 = __builtin_ia32_loaddqu(needles.data());
// The thresholds below were empirically determined by benchmarking.
// This is not an exact science since it depends on the CPU, the size of
// needles, and the size of haystack.
- if (haystack.size() == 1 ||
- (haystack.size() < 4 && needles.size() <= 16)) {
- return qfind_first_of(haystack, needles, asciiCaseSensitive);
- } else if ((needles.size() >= 4 && haystack.size() <= 10) ||
+ if ((needles.size() >= 4 && haystack.size() <= 10) ||
(needles.size() >= 16 && haystack.size() <= 64) ||
needles.size() >= 32) {
return qfind_first_byte_of_byteset(haystack, needles);
}
-
- return qfind_first_byte_of_memchr(haystack, needles);
+ return qfind_first_of(haystack, needles, asciiCaseSensitive);
}
} // namespace detail