Commit a30215d9 authored by Lucian Grijincu's avatar Lucian Grijincu Committed by Facebook Github Bot

folly: experimental: ABI-break: replace deprecated folly::StringPieceHash with folly::Hash

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
parent b18fddc4
...@@ -18,9 +18,13 @@ ...@@ -18,9 +18,13 @@
#pragma once #pragma once
#include <functional>
#include <initializer_list> #include <initializer_list>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include <utility>
#include <folly/Hash.h>
#include <folly/Range.h> #include <folly/Range.h>
#include <folly/experimental/StringKeyedCommon.h> #include <folly/experimental/StringKeyedCommon.h>
...@@ -33,13 +37,14 @@ namespace folly { ...@@ -33,13 +37,14 @@ namespace folly {
* It uses kind of hack: string pointed by StringPiece is copied when * It uses kind of hack: string pointed by StringPiece is copied when
* StringPiece is inserted into map * StringPiece is inserted into map
*/ */
template <class Value, template <
class Hash = StringPieceHash, class Value,
class Hash = Hash,
class Eq = std::equal_to<StringPiece>, class Eq = std::equal_to<StringPiece>,
class Alloc = std::allocator<std::pair<const StringPiece, Value>>> class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
class StringKeyedUnorderedMap class StringKeyedUnorderedMap
: private std::unordered_map<StringPiece, Value, Hash, Eq, Alloc> { : private std::unordered_map<StringPiece, Value, Hash, Eq, Alloc> {
private: private:
using Base = std::unordered_map<StringPiece, Value, Hash, Eq, Alloc>; using Base = std::unordered_map<StringPiece, Value, Hash, Eq, Alloc>;
public: public:
......
...@@ -18,9 +18,13 @@ ...@@ -18,9 +18,13 @@
#pragma once #pragma once
#include <functional>
#include <initializer_list> #include <initializer_list>
#include <memory> #include <memory>
#include <unordered_set> #include <unordered_set>
#include <utility>
#include <folly/Hash.h>
#include <folly/Range.h> #include <folly/Range.h>
#include <folly/experimental/StringKeyedCommon.h> #include <folly/experimental/StringKeyedCommon.h>
...@@ -33,7 +37,8 @@ namespace folly { ...@@ -33,7 +37,8 @@ namespace folly {
* It uses kind of hack: string pointed by StringPiece is copied when * It uses kind of hack: string pointed by StringPiece is copied when
* StringPiece is inserted into set * StringPiece is inserted into set
*/ */
template <class Hasher = StringPieceHash, template <
class Hasher = Hash,
class Eq = std::equal_to<StringPiece>, class Eq = std::equal_to<StringPiece>,
class Alloc = std::allocator<folly::StringPiece>> class Alloc = std::allocator<folly::StringPiece>>
class BasicStringKeyedUnorderedSet class BasicStringKeyedUnorderedSet
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <folly/Hash.h>
#include <folly/Range.h> #include <folly/Range.h>
#include <folly/portability/GFlags.h> #include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
...@@ -113,17 +114,21 @@ typedef MemoryLeakCheckerAllocator<std::allocator<char>> KeyLeakChecker; ...@@ -113,17 +114,21 @@ typedef MemoryLeakCheckerAllocator<std::allocator<char>> KeyLeakChecker;
typedef MemoryLeakCheckerAllocator< typedef MemoryLeakCheckerAllocator<
std::allocator<std::pair<const StringPiece, int>>> ValueLeakChecker; std::allocator<std::pair<const StringPiece, int>>> ValueLeakChecker;
typedef StringKeyedUnorderedMap<int, folly::StringPieceHash, typedef StringKeyedUnorderedMap<
std::equal_to<StringPiece>, ValueLeakChecker> int,
folly::Hash,
std::equal_to<StringPiece>,
ValueLeakChecker>
LeakCheckedUnorderedMap; LeakCheckedUnorderedMap;
typedef StringKeyedSetBase<std::less<StringPiece>, ValueLeakChecker> LeakCheckedSet; typedef StringKeyedSetBase<std::less<StringPiece>, ValueLeakChecker>
LeakCheckedSet;
typedef StringKeyedMap<int, std::less<StringPiece>, typedef StringKeyedMap<int, std::less<StringPiece>, ValueLeakChecker>
ValueLeakChecker> LeakCheckedMap; LeakCheckedMap;
using LeakCheckedUnorderedSet = BasicStringKeyedUnorderedSet< using LeakCheckedUnorderedSet = BasicStringKeyedUnorderedSet<
folly::StringPieceHash, folly::Hash,
std::equal_to<folly::StringPiece>, std::equal_to<folly::StringPiece>,
ValueLeakChecker>; ValueLeakChecker>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment