Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: mojo/public/cpp/bindings/lib/map_serialization.h

Issue 1683863002: Mojo C++ bindings: make mojo::Map<K,V> more friendly with std::map<K,V>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/map_internal.h ('k') | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/map_internal.h ('k') | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698