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();
// 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