folly: experimental: ABI-break: replace deprecated folly::StringPieceHash with folly...
authorLucian Grijincu <lucian@fb.com>
Wed, 5 Oct 2016 04:28:20 +0000 (21:28 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 5 Oct 2016 04:38:30 +0000 (21:38 -0700)
Summary:
folly::StringPieceHash has a large comment explaining why not to use it, but it's not marked as deprecated.

It's also conveniently named StringPieceHash and not StringPieceHashDEPRECATED so new uses appear from time to time.

Let's nuke the default before it does more damage.

Reviewed By: yfeldblum

Differential Revision: D3967239

fbshipit-source-id: 04b0564fdf2a70f1195ef2afdff092bc63cde975

folly/experimental/StringKeyedUnorderedMap.h
folly/experimental/StringKeyedUnorderedSet.h
folly/experimental/test/StringKeyedTest.cpp

index 475c1aecc52105c13204408509b399e6f5100276..c67b9089f066b05beeafcf64b21692205da89c75 100644 (file)
 
 #pragma once
 
+#include <functional>
 #include <initializer_list>
 #include <memory>
 #include <unordered_map>
+#include <utility>
+
+#include <folly/Hash.h>
 #include <folly/Range.h>
 #include <folly/experimental/StringKeyedCommon.h>
 
@@ -33,13 +37,14 @@ namespace folly {
  * It uses kind of hack: string pointed by StringPiece is copied when
  * StringPiece is inserted into map
  */
-template <class Value,
-          class Hash = StringPieceHash,
-          class Eq = std::equal_to<StringPiece>,
-          class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
+template <
+    class Value,
+    class Hash = Hash,
+    class Eq = std::equal_to<StringPiece>,
+    class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
 class StringKeyedUnorderedMap
     : private std::unordered_map<StringPiece, Value, Hash, Eq, Alloc> {
-private:
+ private:
   using Base = std::unordered_map<StringPiece, Value, Hash, Eq, Alloc>;
 
 public:
index e52feaa58546229a858913e425324017509ff8d7..2a388e769b3df3a0cee480e1d6878a0c823f33ff 100644 (file)
 
 #pragma once
 
+#include <functional>
 #include <initializer_list>
 #include <memory>
 #include <unordered_set>
+#include <utility>
+
+#include <folly/Hash.h>
 #include <folly/Range.h>
 #include <folly/experimental/StringKeyedCommon.h>
 
@@ -33,9 +37,10 @@ namespace folly {
  * It uses kind of hack: string pointed by StringPiece is copied when
  * StringPiece is inserted into set
  */
-template <class Hasher = StringPieceHash,
-          class Eq = std::equal_to<StringPiece>,
-          class Alloc = std::allocator<folly::StringPiece>>
+template <
+    class Hasher = Hash,
+    class Eq = std::equal_to<StringPiece>,
+    class Alloc = std::allocator<folly::StringPiece>>
 class BasicStringKeyedUnorderedSet
     : private std::unordered_set<StringPiece, Hasher, Eq, Alloc> {
   using Base = std::unordered_set<StringPiece, Hasher, Eq, Alloc>;
index 446e74a392dfe82352fa47f896c70364701294c3..afd5a2c0c2462bd4aa4ca13e9e9b9f57fd6af2f4 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <glog/logging.h>
 
+#include <folly/Hash.h>
 #include <folly/Range.h>
 #include <folly/portability/GFlags.h>
 #include <folly/portability/GTest.h>
@@ -113,19 +114,23 @@ typedef MemoryLeakCheckerAllocator<std::allocator<char>> KeyLeakChecker;
 typedef MemoryLeakCheckerAllocator<
   std::allocator<std::pair<const StringPiece, int>>> ValueLeakChecker;
 
-typedef StringKeyedUnorderedMap<int, folly::StringPieceHash,
-                                std::equal_to<StringPiece>, ValueLeakChecker>
-  LeakCheckedUnorderedMap;
+typedef StringKeyedUnorderedMap<
+    int,
+    folly::Hash,
+    std::equal_to<StringPiece>,
+    ValueLeakChecker>
+    LeakCheckedUnorderedMap;
 
-typedef StringKeyedSetBase<std::less<StringPiece>, ValueLeakChecker> LeakCheckedSet;
+typedef StringKeyedSetBase<std::less<StringPiece>, ValueLeakChecker>
+    LeakCheckedSet;
 
-typedef StringKeyedMap<int, std::less<StringPiece>,
-                       ValueLeakChecker> LeakCheckedMap;
+typedef StringKeyedMap<int, std::less<StringPiece>, ValueLeakChecker>
+    LeakCheckedMap;
 
 using LeakCheckedUnorderedSet = BasicStringKeyedUnorderedSet<
-  folly::StringPieceHash,
-  std::equal_to<folly::StringPiece>,
-  ValueLeakChecker>;
+    folly::Hash,
+    std::equal_to<folly::StringPiece>,
+    ValueLeakChecker>;
 
 TEST(StringKeyedUnorderedMapTest, sanity) {
   LeakCheckedUnorderedMap map;