OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_HASH_UTIL_H_ | |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_HASH_UTIL_H_ | |
7 | |
8 #include <type_traits> | |
9 | |
10 #include "mojo/public/cpp/bindings/lib/hash_util.h" | |
11 #include "mojo/public/cpp/bindings/struct_ptr.h" | |
12 #include "third_party/WebKit/Source/wtf/HashFunctions.h" | |
13 #include "third_party/WebKit/Source/wtf/text/StringHash.h" | |
14 #include "third_party/WebKit/Source/wtf/text/WTFString.h" | |
15 | |
16 namespace mojo { | |
17 namespace internal { | |
18 | |
19 template <> | |
20 struct HashTraits<WTF::String, false> { | |
21 static size_t Hash(size_t seed, const WTF::String& value) { | |
22 return HashCombine(seed, WTF::StringHash::hash(value)); | |
23 } | |
24 }; | |
25 | |
26 template <typename T> | |
27 struct StructPtrHashFn { | |
28 static unsigned hash(const StructPtr<T>& value) { | |
29 return value.Hash(kHashSeed); | |
30 } | |
31 static bool equal(const StructPtr<T>& left, const StructPtr<T>& right) { | |
32 return left.Equals(right); | |
33 } | |
34 static const bool safeToCompareToEmptyOrDeleted = false; | |
35 }; | |
36 | |
37 template <typename T> | |
38 struct InlinedStructPtrHashFn { | |
39 static unsigned hash(const InlinedStructPtr<T>& value) { | |
40 return value.Hash(kHashSeed); | |
41 } | |
42 static bool equal(const InlinedStructPtr<T>& left, | |
43 const InlinedStructPtr<T>& right) { | |
44 return left.Equals(right); | |
45 } | |
46 static const bool safeToCompareToEmptyOrDeleted = false; | |
47 }; | |
48 | |
49 } // namespace internal | |
50 } // namespace mojo | |
51 | |
52 namespace WTF { | |
53 | |
54 template <typename T> | |
55 struct DefaultHash<mojo::StructPtr<T>> { | |
56 using Hash = mojo::internal::StructPtrHashFn<T>; | |
57 }; | |
58 | |
59 template <typename T> | |
60 struct HashTraits<mojo::StructPtr<T>> | |
61 : public GenericHashTraits<mojo::StructPtr<T>> { | |
62 static const bool hasIsEmptyValueFunction = true; | |
63 static bool isEmptyValue(const mojo::StructPtr<T>& value) { | |
64 return value.is_null(); | |
65 } | |
66 static void constructDeletedValue(mojo::StructPtr<T>& slot, bool) { | |
67 mojo::internal::StructPtrWTFHelper<T>::ConstructDeletedValue(slot); | |
68 } | |
69 static bool isDeletedValue(const mojo::StructPtr<T>& value) { | |
70 return mojo::internal::StructPtrWTFHelper<T>::ConstructDeletedValue(value); | |
Sam McNally
2016/09/22 05:40:51
Wat?
tibell
2016/09/22 07:18:33
Done.
| |
71 } | |
72 }; | |
73 | |
74 template <typename T> | |
75 struct DefaultHash<mojo::InlinedStructPtr<T>> { | |
76 using Hash = mojo::internal::InlinedStructPtrHashFn<T>; | |
77 }; | |
78 | |
79 template <typename T> | |
80 struct HashTraits<mojo::InlinedStructPtr<T>> | |
81 : public GenericHashTraits<mojo::InlinedStructPtr<T>> { | |
82 static const bool hasIsEmptyValueFunction = true; | |
83 static bool isEmptyValue(const mojo::InlinedStructPtr<T>& value) { | |
84 return value.is_null(); | |
85 } | |
86 static void constructDeletedValue(mojo::InlinedStructPtr<T>& slot, bool) { | |
87 mojo::internal::InlinedStructPtrWTFHelper<T>::ConstructDeletedValue(slot); | |
88 } | |
89 static bool isDeletedValue(const mojo::InlinedStructPtr<T>& value) { | |
90 return mojo::internal::InlinedStructPtrWTFHelper<T>::ConstructDeletedValue( | |
Sam McNally
2016/09/22 05:40:51
Ditto.
tibell
2016/09/22 07:18:33
Done.
| |
91 value); | |
92 } | |
93 }; | |
94 | |
95 } // namespace WTF | |
96 | |
97 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_HASH_UTIL_H_ | |
OLD | NEW |