OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MAP_SERIALIZATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 sizeof(internal::ArrayHeader) + | 113 sizeof(internal::ArrayHeader) + |
114 internal::MapSerializer<MapKey, DataKey>::GetBaseArraySize(count); | 114 internal::MapSerializer<MapKey, DataKey>::GetBaseArraySize(count); |
115 size_t value_base_size = | 115 size_t value_base_size = |
116 sizeof(internal::ArrayHeader) + | 116 sizeof(internal::ArrayHeader) + |
117 internal::MapSerializer<MapValue, DataValue>::GetBaseArraySize(count); | 117 internal::MapSerializer<MapValue, DataValue>::GetBaseArraySize(count); |
118 | 118 |
119 size_t key_data_size = 0; | 119 size_t key_data_size = 0; |
120 size_t value_data_size = 0; | 120 size_t value_data_size = 0; |
121 for (auto it = input.begin(); it != input.end(); ++it) { | 121 for (auto it = input.begin(); it != input.end(); ++it) { |
122 key_data_size += | 122 key_data_size += |
123 internal::MapSerializer<MapKey, DataKey>::GetItemSize(it.GetKey()); | 123 internal::MapSerializer<MapKey, DataKey>::GetItemSize(it->first); |
124 value_data_size += | 124 value_data_size += |
125 internal::MapSerializer<MapValue, DataValue>::GetItemSize( | 125 internal::MapSerializer<MapValue, DataValue>::GetItemSize(it->second); |
126 it.GetValue()); | |
127 } | 126 } |
128 | 127 |
129 return struct_overhead + key_base_size + key_data_size + value_base_size + | 128 return struct_overhead + key_base_size + key_data_size + value_base_size + |
130 value_data_size; | 129 value_data_size; |
131 } | 130 } |
132 | 131 |
133 // We don't need an ArrayValidateParams instance for key validation since | 132 // We don't need an ArrayValidateParams instance for key validation since |
134 // we can deduce it from the Key type. (which can only be primitive types or | 133 // we can deduce it from the Key type. (which can only be primitive types or |
135 // non-nullable strings.) | 134 // non-nullable strings.) |
136 template <typename MapKey, | 135 template <typename MapKey, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 *output = Map<MapKey, MapValue>(std::move(keys), std::move(values)); | 184 *output = Map<MapKey, MapValue>(std::move(keys), std::move(values)); |
186 } else { | 185 } else { |
187 output->reset(); | 186 output->reset(); |
188 } | 187 } |
189 return success; | 188 return success; |
190 } | 189 } |
191 | 190 |
192 } // namespace mojo | 191 } // namespace mojo |
193 | 192 |
194 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ | 193 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_SERIALIZATION_H_ |
OLD | NEW |