Revert "[folly] TLS cache for AccessSpreader"
[folly.git] / folly / Range.cpp
index 343ba7284c21bad813148861a11b1903e1002f72..9e8944f9e8372408380740d4f3b6d6b5697c3e75 100644 (file)
@@ -42,26 +42,6 @@ std::ostream& operator<<(std::ostream& os, const MutableStringPiece piece) {
   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
@@ -95,15 +75,13 @@ size_t qfind_first_byte_of_needles16(const StringPiece haystack,
   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());
@@ -278,16 +256,12 @@ size_t qfind_first_byte_of_nosse(const StringPiece haystack,
   // 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