From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WTF/wtf/HashFunctions.h | 52 +++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'Source/WTF/wtf/HashFunctions.h') diff --git a/Source/WTF/wtf/HashFunctions.h b/Source/WTF/wtf/HashFunctions.h index 471a8f375..462f19a81 100644 --- a/Source/WTF/wtf/HashFunctions.h +++ b/Source/WTF/wtf/HashFunctions.h @@ -21,8 +21,9 @@ #ifndef WTF_HashFunctions_h #define WTF_HashFunctions_h -#include #include +#include +#include namespace WTF { @@ -119,21 +120,37 @@ namespace WTF { // pointer identity hash function - template struct PtrHash { - static unsigned hash(T key) - { - return IntHash::hash(reinterpret_cast(key)); - } - static bool equal(T a, T b) { return a == b; } + template + struct PtrHashBase; + + template + struct PtrHashBase { + typedef T PtrType; + + static unsigned hash(PtrType key) { return IntHash::hash(reinterpret_cast(key)); } + static bool equal(PtrType a, PtrType b) { return a == b; } static const bool safeToCompareToEmptyOrDeleted = true; }; - template struct PtrHash> : PtrHash { - using PtrHash::hash; - static unsigned hash(const RefPtr

& key) { return hash(key.get()); } - using PtrHash::equal; - static bool equal(const RefPtr

& a, const RefPtr

& b) { return a == b; } - static bool equal(P* a, const RefPtr

& b) { return a == b; } - static bool equal(const RefPtr

& a, P* b) { return a == b; } + + template + struct PtrHashBase { + typedef typename GetPtrHelper::PtrType PtrType; + + static unsigned hash(PtrType key) { return IntHash::hash(reinterpret_cast(key)); } + static bool equal(PtrType a, PtrType b) { return a == b; } + static const bool safeToCompareToEmptyOrDeleted = true; + + static unsigned hash(const T& key) { return hash(getPtr(key)); } + static bool equal(const T& a, const T& b) { return getPtr(a) == getPtr(b); } + static bool equal(PtrType a, const T& b) { return a == getPtr(b); } + static bool equal(const T& a, PtrType b) { return getPtr(a) == b; } + }; + + template struct PtrHash : PtrHashBase::value> { + }; + + template struct PtrHash> : PtrHashBase, IsSmartPtr>::value> { + static const bool safeToCompareToEmptyOrDeleted = false; }; // default hash function for each type @@ -149,8 +166,7 @@ namespace WTF { { return DefaultHash::Hash::equal(a.first, b.first) && DefaultHash::Hash::equal(a.second, b.second); } - static const bool safeToCompareToEmptyOrDeleted = DefaultHash::Hash::safeToCompareToEmptyOrDeleted - && DefaultHash::Hash::safeToCompareToEmptyOrDeleted; + static const bool safeToCompareToEmptyOrDeleted = DefaultHash::Hash::safeToCompareToEmptyOrDeleted && DefaultHash::Hash::safeToCompareToEmptyOrDeleted; }; template struct IntPairHash { @@ -161,6 +177,7 @@ namespace WTF { // make IntHash the default hash function for many integer types + template<> struct DefaultHash { typedef IntHash Hash; }; template<> struct DefaultHash { typedef IntHash Hash; }; template<> struct DefaultHash { typedef IntHash Hash; }; template<> struct DefaultHash { typedef IntHash Hash; }; @@ -181,6 +198,9 @@ namespace WTF { template struct DefaultHash { typedef PtrHash Hash; }; template struct DefaultHash> { typedef PtrHash> Hash; }; + template struct DefaultHash> { typedef PtrHash> Hash; }; + + template struct DefaultHash> { typedef PtrHash> Hash; }; // make IntPairHash the default hash function for pairs of (at most) 32-bit integers. -- cgit v1.2.1