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 @@
#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:
......
......@@ -18,9 +18,13 @@
#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>;
......
......@@ -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;
......
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