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

Unified Diff: mojo/public/cpp/bindings/lib/array_internal.h

Issue 2112093002: Mojo C++ bindings: Merge EncodePointers/DecodePointers into Serialize/Deserialize, respectively. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@61_array_fix
Patch Set: . Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/lib/array_serialization.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/array_internal.h
diff --git a/mojo/public/cpp/bindings/lib/array_internal.h b/mojo/public/cpp/bindings/lib/array_internal.h
index adf5e32038f44e774eb277df15d06b743fa81528..ba6d16ea21499bf037d9eab246195284c9b57b2d 100644
--- a/mojo/public/cpp/bindings/lib/array_internal.h
+++ b/mojo/public/cpp/bindings/lib/array_internal.h
@@ -58,28 +58,6 @@ struct ArrayDataTraits {
}
};
-template <typename P>
-struct ArrayDataTraits<P*> {
- using StorageType = Pointer<P>;
- using Ref = P*&;
- using ConstRef = P* const&;
-
- static const uint32_t kMaxNumElements =
- (std::numeric_limits<uint32_t>::max() - sizeof(ArrayHeader)) /
- sizeof(StorageType);
-
- static uint32_t GetStorageSize(uint32_t num_elements) {
- DCHECK(num_elements <= kMaxNumElements);
- return sizeof(ArrayHeader) + sizeof(StorageType) * num_elements;
- }
- static Ref ToRef(StorageType* storage, size_t offset) {
- return storage[offset].ptr;
- }
- static ConstRef ToConstRef(const StorageType* storage, size_t offset) {
- return storage[offset].ptr;
- }
-};
-
// Specialization of Arrays for bools, optimized for space. It has the
// following differences from a generalized Array:
// * Each element takes up a single bit of memory.
@@ -141,12 +119,6 @@ template <typename T>
struct ArraySerializationHelper<T, false, false> {
using ElementType = typename ArrayDataTraits<T>::StorageType;
- static void EncodePointers(const ArrayHeader* header,
- ElementType* elements) {}
-
- static void DecodePointers(const ArrayHeader* header,
- ElementType* elements) {}
-
static bool ValidateElements(const ArrayHeader* header,
const ElementType* elements,
ValidationContext* validation_context,
@@ -172,12 +144,6 @@ template <typename T>
struct ArraySerializationHelper<T, false, true> {
using ElementType = typename ArrayDataTraits<T>::StorageType;
- static void EncodePointers(const ArrayHeader* header,
- ElementType* elements) {}
-
- static void DecodePointers(const ArrayHeader* header,
- ElementType* elements) {}
-
static bool ValidateElements(const ArrayHeader* header,
const ElementType* elements,
ValidationContext* validation_context,
@@ -209,19 +175,9 @@ struct ArraySerializationHelper<T, false, true> {
}
};
-template <typename P>
-struct ArraySerializationHelper<P*, false, false> {
- using ElementType = typename ArrayDataTraits<P*>::StorageType;
-
- static void EncodePointers(const ArrayHeader* header, ElementType* elements) {
- for (uint32_t i = 0; i < header->num_elements; ++i)
- Encode(&elements[i]);
- }
-
- static void DecodePointers(const ArrayHeader* header, ElementType* elements) {
- for (uint32_t i = 0; i < header->num_elements; ++i)
- Decode(&elements[i]);
- }
+template <typename T>
+struct ArraySerializationHelper<Pointer<T>, false, false> {
+ using ElementType = typename ArrayDataTraits<Pointer<T>>::StorageType;
static bool ValidateElements(const ArrayHeader* header,
const ElementType* elements,
@@ -237,7 +193,7 @@ struct ArraySerializationHelper<P*, false, false> {
i).c_str());
return false;
}
- if (!ValidateCaller<P>::Run(elements[i], validation_context,
+ if (!ValidateCaller<T>::Run(elements[i], validation_context,
validate_params->element_validate_params)) {
return false;
}
@@ -246,9 +202,11 @@ struct ArraySerializationHelper<P*, false, false> {
}
private:
- template <typename T>
+ template <typename U,
+ bool is_array_or_map = IsSpecializationOf<Array_Data, U>::value ||
+ IsSpecializationOf<Map_Data, U>::value>
struct ValidateCaller {
- static bool Run(const Pointer<T>& data,
+ static bool Run(const Pointer<U>& data,
ValidationContext* validation_context,
const ContainerValidateParams* validate_params) {
DCHECK(!validate_params)
@@ -258,21 +216,12 @@ struct ArraySerializationHelper<P*, false, false> {
}
};
- template <typename Key, typename Value>
- struct ValidateCaller<Map_Data<Key, Value>> {
- static bool Run(const Pointer<Map_Data<Key, Value>>& data,
+ template <typename U>
+ struct ValidateCaller<U, true> {
+ static bool Run(const Pointer<U>& data,
ValidationContext* validation_context,
const ContainerValidateParams* validate_params) {
- return ValidateMap(data, validation_context, validate_params);
- }
- };
-
- template <typename T>
- struct ValidateCaller<Array_Data<T>> {
- static bool Run(const Pointer<Array_Data<T>>& data,
- ValidationContext* validation_context,
- const ContainerValidateParams* validate_params) {
- return ValidateArray(data, validation_context, validate_params);
+ return ValidateContainer(data, validation_context, validate_params);
}
};
};
@@ -281,16 +230,6 @@ template <typename U>
struct ArraySerializationHelper<U, true, false> {
using ElementType = typename ArrayDataTraits<U>::StorageType;
- static void EncodePointers(const ArrayHeader* header, ElementType* elements) {
- for (uint32_t i = 0; i < header->num_elements; ++i)
- elements[i].EncodePointers();
- }
-
- static void DecodePointers(const ArrayHeader* header, ElementType* elements) {
- for (uint32_t i = 0; i < header->num_elements; ++i)
- elements[i].DecodePointers();
- }
-
static bool ValidateElements(const ArrayHeader* header,
const ElementType* elements,
ValidationContext* validation_context,
@@ -406,9 +345,6 @@ class Array_Data {
reinterpret_cast<const char*>(this) + sizeof(*this));
}
- void EncodePointers() { Helper::EncodePointers(&header_, storage()); }
- void DecodePointers() { Helper::DecodePointers(&header_, storage()); }
-
private:
Array_Data(uint32_t num_bytes, uint32_t num_elements) {
header_.num_bytes = num_bytes;
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/lib/array_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698