Fix FBStringTest build failure and hash computation for wchar
authorQinfan Wu <wqfish@fb.com>
Sat, 16 Jul 2016 05:52:10 +0000 (22:52 -0700)
committerFacebook Github Bot 6 <facebook-github-bot-6-bot@fb.com>
Sat, 16 Jul 2016 05:53:27 +0000 (22:53 -0700)
Summary:
Getting some build errors when doing `buck test folly/...`. This seems to be fixing it.

  folly/test/FBStringTest.cpp:1290:23: error: unknown type name 'basic_fbstring'; did you mean 'basic_fstream'?
    using u16fbstring = basic_fbstring<char16_t>;
                        ^~~~~~~~~~~~~~
                        basic_fstream

Also the test `testHashChar16` was failing because only part of the string is used when computing hash.

Reviewed By: yfeldblum

Differential Revision: D3575858

fbshipit-source-id: cdd5bdb9653d50beaf0ec82b659d31354b345441

folly/FBString.h
folly/test/FBStringTest.cpp

index 9a50e29958d27496fd49fa19530c029d44e3aced..b3ec8f43eff94d90987e1fefd3dc4e810dca4fd4 100644 (file)
@@ -2438,12 +2438,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
index 8767b28ff61831cbfa77774901cadd818e70edab..56b6ef0cb88f296620f5d323f214d3cd1b21abf2 100644 (file)
@@ -1287,7 +1287,7 @@ TEST(FBString, testHash) {
 
 #if FOLLY_HAVE_WCHAR_SUPPORT
 TEST(FBString, testHashChar16) {
-  using u16fbstring = basic_fbstring<char16_t>;
+  using u16fbstring = folly::basic_fbstring<char16_t>;
   u16fbstring a;
   u16fbstring b;
   a.push_back(0);