Chromium Code Reviews| Index: mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h |
| diff --git a/mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h b/mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h |
| index edbf27b7d3059e0a1f1429af64a2a62f68688ae3..97ee18ac7e7cd13967ec156bfa6d0f3ed28b9456 100644 |
| --- a/mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h |
| +++ b/mojo/public/cpp/bindings/lib/wtf_clone_equals_util.h |
| @@ -8,9 +8,12 @@ |
| #include <type_traits> |
| #include "mojo/public/cpp/bindings/lib/clone_equals_util.h" |
| +#include "mojo/public/cpp/bindings/struct_ptr.h" |
| +#include "third_party/WebKit/Source/wtf/HashFunctions.h" |
| #include "third_party/WebKit/Source/wtf/HashMap.h" |
| #include "third_party/WebKit/Source/wtf/Optional.h" |
| #include "third_party/WebKit/Source/wtf/Vector.h" |
| +#include "third_party/WebKit/Source/wtf/text/StringHash.h" |
| #include "third_party/WebKit/Source/wtf/text/WTFString.h" |
| namespace mojo { |
| @@ -70,7 +73,103 @@ struct EqualsTraits<WTF::HashMap<K, V>, false> { |
| } |
| }; |
| +template <typename T> |
| +struct HashTraits<WTF::Vector<T>, false> { |
|
Sam McNally
2016/09/21 04:57:58
Ditto for these two.
tibell
2016/09/21 07:10:53
Done.
|
| + static size_t Hash(size_t seed, const WTF::Vector<T>& value) { |
| + for (size_t i = 0; i < value.size(); ++i) { |
| + seed = Hash(seed, value[i]); |
| + } |
| + return seed; |
| + } |
| +}; |
| + |
| +template <typename K, typename V> |
| +struct HashTraits<WTF::HashMap<K, V>, false> { |
| + static size_t Hash(size_t seed, const WTF::HashMap<K, V>& value) { |
| + for (auto iter = value.begin(); iter != value.end(); ++iter) { |
| + seed = Hash(seed, iter->key); |
| + seed = Hash(seed, iter->value); |
| + } |
| + return seed; |
| + } |
| +}; |
| + |
| +template <> |
| +struct HashTraits<WTF::String, false> { |
| + static size_t Hash(size_t seed, const WTF::String& value) { |
| + return HashCombine(seed, WTF::StringHash::hash(value)); |
| + } |
| +}; |
| + |
| +template <typename T> |
| +struct StructPtrHashFn { |
| + static unsigned hash(const mojo::StructPtr<T>& value) { |
|
yzshen1
2016/09/20 23:44:39
nit: namespace is not needed (here and changes bel
tibell
2016/09/21 07:10:53
Done.
These now all uses hashing/equality on the
|
| + return mojo::internal::Hash(mojo::internal::kHashSeed, *value.get()); |
|
yzshen1
2016/09/20 23:44:39
*value.get(): Is it possible to dereference null p
tibell
2016/09/21 07:10:53
Done.
|
| + } |
| + static bool equal(const mojo::StructPtr<T>& left, |
| + const mojo::StructPtr<T>& right) { |
| + return left->Equals(*right); |
|
yzshen1
2016/09/20 23:44:39
ditto
tibell
2016/09/21 07:10:53
Done.
|
| + } |
| + static const bool safeToCompareToEmptyOrDeleted = false; |
| +}; |
| + |
| +template <typename T> |
| +struct InlinedStructPtrHashFn { |
| + static unsigned hash(const mojo::InlinedStructPtr<T>& value) { |
| + return mojo::internal::Hash(mojo::internal::kHashSeed, *value.get()); |
|
yzshen1
2016/09/20 23:44:39
ditto
tibell
2016/09/21 07:10:53
Done.
|
| + } |
| + static bool equal(const mojo::InlinedStructPtr<T>& left, |
| + const mojo::InlinedStructPtr<T>& right) { |
| + return left->Equals(*right); |
|
yzshen1
2016/09/20 23:44:39
ditto
tibell
2016/09/21 07:10:53
Done.
|
| + } |
| + static const bool safeToCompareToEmptyOrDeleted = false; |
| +}; |
| + |
| } // namespace internal |
| } // namespace mojo |
| +namespace WTF { |
| + |
| +template <typename T> |
| +struct DefaultHash<mojo::StructPtr<T>> { |
| + using Hash = mojo::internal::StructPtrHashFn<T>; |
| +}; |
| + |
| +template <typename T> |
| +struct HashTraits<mojo::StructPtr<T>> |
| + : public GenericHashTraits<mojo::StructPtr<T>> { |
| + static const bool hasIsEmptyValueFunction = true; |
| + static bool isEmptyValue(const mojo::StructPtr<T>& value) { |
| + return value.is_null(); |
| + } |
| + static void constructDeletedValue(mojo::StructPtr<T>& slot, bool) { |
| + mojo::StructPtr<T>::constructDeletedValue(slot); |
| + } |
| + static bool isDeletedValue(const mojo::StructPtr<T>& value) { |
| + return value.isHashTableDeletedValue(); |
| + } |
| +}; |
| + |
| +template <typename T> |
| +struct DefaultHash<mojo::InlinedStructPtr<T>> { |
| + using Hash = mojo::internal::InlinedStructPtrHashFn<T>; |
| +}; |
| + |
| +template <typename T> |
| +struct HashTraits<mojo::InlinedStructPtr<T>> |
| + : public GenericHashTraits<mojo::InlinedStructPtr<T>> { |
| + static const bool hasIsEmptyValueFunction = true; |
| + static bool isEmptyValue(const mojo::InlinedStructPtr<T>& value) { |
| + return value.is_null(); |
| + } |
| + static void constructDeletedValue(mojo::InlinedStructPtr<T>& slot, bool) { |
| + mojo::InlinedStructPtr<T>::constructDeletedValue(slot); |
| + } |
| + static bool isDeletedValue(const mojo::InlinedStructPtr<T>& value) { |
| + return value.isHashTableDeletedValue(); |
| + } |
| +}; |
| + |
| +} // namespace WTF |
| + |
| #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_ |