An intro to the upgrade mutex in the Synchronized docs
[folly.git] / folly / FBString.h
index 9a50e29958d27496fd49fa19530c029d44e3aced..8d6f19c2b6c6761b358439182de3988cf4d19e8b 100644 (file)
@@ -1768,11 +1768,12 @@ public:
 
   size_type find(const value_type* needle, const size_type pos,
                  const size_type nsize) const {
-    if (!nsize) return pos;
     auto const size = this->size();
     // nsize + pos can overflow (eg pos == npos), guard against that by checking
     // that nsize + pos does not wrap around.
     if (nsize + pos > size || nsize + pos < pos) return npos;
+
+    if (nsize == 0) return pos;
     // Don't use std::search, use a Boyer-Moore-like trick by comparing
     // the last characters first
     auto const haystack = data();
@@ -2438,12 +2439,12 @@ _GLIBCXX_END_NAMESPACE_VERSION
 // Handle interaction with different C++ standard libraries, which
 // expect these types to be in different namespaces.
 
-#define FOLLY_FBSTRING_HASH1(T) \
-  template <> \
-  struct hash< ::folly::basic_fbstring<T> > { \
-    size_t operator()(const ::folly::basic_fbstring<T>& s) const { \
-      return ::folly::hash::fnv32_buf(s.data(), s.size()); \
-    } \
+#define FOLLY_FBSTRING_HASH1(T)                                        \
+  template <>                                                          \
+  struct hash< ::folly::basic_fbstring<T>> {                            \
+    size_t operator()(const ::folly::basic_fbstring<T>& s) const {     \
+      return ::folly::hash::fnv32_buf(s.data(), s.size() * sizeof(T)); \
+    }                                                                  \
   };
 
 // The C++11 standard says that these four are defined