| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_ |
| 7 | 7 |
| 8 #include <type_traits> | 8 #include <type_traits> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/clone_traits.h" | 10 #include "mojo/public/cpp/bindings/clone_traits.h" |
| 11 #include "mojo/public/cpp/bindings/lib/equals_traits.h" | 11 #include "mojo/public/cpp/bindings/equals_traits.h" |
| 12 #include "third_party/WebKit/Source/platform/wtf/HashMap.h" | 12 #include "third_party/WebKit/Source/platform/wtf/HashMap.h" |
| 13 #include "third_party/WebKit/Source/platform/wtf/Optional.h" | 13 #include "third_party/WebKit/Source/platform/wtf/Optional.h" |
| 14 #include "third_party/WebKit/Source/platform/wtf/Vector.h" | 14 #include "third_party/WebKit/Source/platform/wtf/Vector.h" |
| 15 #include "third_party/WebKit/Source/platform/wtf/text/WTFString.h" | 15 #include "third_party/WebKit/Source/platform/wtf/text/WTFString.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 | 18 |
| 19 template <typename T> | 19 template <typename T> |
| 20 struct CloneTraits<WTF::Vector<T>, false> { | 20 struct CloneTraits<WTF::Vector<T>, false> { |
| 21 static WTF::Vector<T> Clone(const WTF::Vector<T>& input) { | 21 static WTF::Vector<T> Clone(const WTF::Vector<T>& input) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 struct CloneTraits<WTF::HashMap<K, V>, false> { | 32 struct CloneTraits<WTF::HashMap<K, V>, false> { |
| 33 static WTF::HashMap<K, V> Clone(const WTF::HashMap<K, V>& input) { | 33 static WTF::HashMap<K, V> Clone(const WTF::HashMap<K, V>& input) { |
| 34 WTF::HashMap<K, V> result; | 34 WTF::HashMap<K, V> result; |
| 35 auto input_end = input.end(); | 35 auto input_end = input.end(); |
| 36 for (auto it = input.begin(); it != input_end; ++it) | 36 for (auto it = input.begin(); it != input_end; ++it) |
| 37 result.add(mojo::Clone(it->key), mojo::Clone(it->value)); | 37 result.add(mojo::Clone(it->key), mojo::Clone(it->value)); |
| 38 return result; | 38 return result; |
| 39 } | 39 } |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 namespace internal { | |
| 43 | |
| 44 template <typename T> | 42 template <typename T> |
| 45 struct EqualsTraits<WTF::Vector<T>, false> { | 43 struct EqualsTraits<WTF::Vector<T>, false> { |
| 46 static bool Equals(const WTF::Vector<T>& a, const WTF::Vector<T>& b) { | 44 static bool Equals(const WTF::Vector<T>& a, const WTF::Vector<T>& b) { |
| 47 if (a.size() != b.size()) | 45 if (a.size() != b.size()) |
| 48 return false; | 46 return false; |
| 49 for (size_t i = 0; i < a.size(); ++i) { | 47 for (size_t i = 0; i < a.size(); ++i) { |
| 50 if (!internal::Equals(a[i], b[i])) | 48 if (!Equals(a[i], b[i])) |
| 51 return false; | 49 return false; |
| 52 } | 50 } |
| 53 return true; | 51 return true; |
| 54 } | 52 } |
| 55 }; | 53 }; |
| 56 | 54 |
| 57 template <typename K, typename V> | 55 template <typename K, typename V> |
| 58 struct EqualsTraits<WTF::HashMap<K, V>, false> { | 56 struct EqualsTraits<WTF::HashMap<K, V>, false> { |
| 59 static bool Equals(const WTF::HashMap<K, V>& a, const WTF::HashMap<K, V>& b) { | 57 static bool Equals(const WTF::HashMap<K, V>& a, const WTF::HashMap<K, V>& b) { |
| 60 if (a.size() != b.size()) | 58 if (a.size() != b.size()) |
| 61 return false; | 59 return false; |
| 62 | 60 |
| 63 auto a_end = a.end(); | 61 auto a_end = a.end(); |
| 64 auto b_end = b.end(); | 62 auto b_end = b.end(); |
| 65 | 63 |
| 66 for (auto iter = a.begin(); iter != a_end; ++iter) { | 64 for (auto iter = a.begin(); iter != a_end; ++iter) { |
| 67 auto b_iter = b.find(iter->key); | 65 auto b_iter = b.find(iter->key); |
| 68 if (b_iter == b_end || !internal::Equals(iter->value, b_iter->value)) | 66 if (b_iter == b_end || !Equals(iter->value, b_iter->value)) |
| 69 return false; | 67 return false; |
| 70 } | 68 } |
| 71 return true; | 69 return true; |
| 72 } | 70 } |
| 73 }; | 71 }; |
| 74 | 72 |
| 75 } // namespace internal | |
| 76 } // namespace mojo | 73 } // namespace mojo |
| 77 | 74 |
| 78 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_ | 75 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_CLONE_EQUALS_UTIL_H_ |
| OLD | NEW |