Chromium Code Reviews| Index: mojo/public/c/bindings/lib/array.c |
| diff --git a/mojo/public/c/bindings/lib/array.c b/mojo/public/c/bindings/lib/array.c |
| index d5a5f651ab2128ef3eaef2c5b209c8c6568f2668..ec6a8bdf1e67e1bedb20f1ce88a8f1e43d1bea87 100644 |
| --- a/mojo/public/c/bindings/lib/array.c |
| +++ b/mojo/public/c/bindings/lib/array.c |
| @@ -7,6 +7,7 @@ |
| #include <assert.h> |
| #include <stddef.h> |
| #include <stdint.h> |
| +#include <string.h> |
| #include "mojo/public/c/bindings/buffer.h" |
| #include "mojo/public/c/bindings/interface.h" |
| @@ -216,3 +217,32 @@ MojomValidationResult MojomArray_Validate( |
| return MOJOM_VALIDATION_ERROR_NONE; |
| } |
| + |
| +struct MojomArrayHeader* MojomArray_DeepCopy( |
| + struct MojomBuffer* buffer, |
| + const struct MojomTypeDescriptorArray* in_type_desc, |
| + struct MojomArrayHeader* in_array) { |
| + assert(in_type_desc); |
| + assert(in_array); |
| + |
| + struct MojomArrayHeader* out_array = |
| + MojomBuffer_Allocate(buffer, in_array->num_bytes); |
|
viettrungluu
2016/08/02 20:15:06
E.g., this could fail. Though at least here you ca
|
| + memcpy(out_array, in_array, in_array->num_bytes); |
| + |
| + // Nothing else to copy for POD types. |
| + if (in_type_desc->elem_type == MOJOM_TYPE_DESCRIPTOR_TYPE_POD) |
| + return out_array; |
| + |
| + for (size_t i = 0; i < in_array->num_elements; i++) { |
| + void* in_elem_data = |
| + array_index_by_type(in_array, in_type_desc->elem_type, i); |
| + void* out_elem_data = |
| + array_index_by_type(out_array, in_type_desc->elem_type, i); |
| + |
| + MojomType_DispatchDeepCopy(buffer, in_type_desc->elem_type, |
|
viettrungluu
2016/08/02 20:15:06
Presumably, this could fail too. But that would po
|
| + in_type_desc->elem_descriptor, in_elem_data, |
| + out_elem_data); |
| + } |
| + |
| + return out_array; |
| +} |