Commit b60976d9 authored by yzshen@chromium.org's avatar yzshen@chromium.org

Add ArrayDataTraits<> specialization for Array_Data<T>*.

Currently, we use wrong storage type for nested arrays. For example, the storage
type of the outer array of int8[][] is
StructPointer<Array_Data<int8_t>>. After this CL it will be
ArrayPointer<int8_t>.

The current code works because StructPointer happens to be of the same
size as ArrayPointer.

(The newly-added tests pass with/without this CL. But I think it is good
to have them.)

BUG=None
TEST=None

Review URL: https://codereview.chromium.org/340223002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278356 0039d316-1c4b-4281-b951-d872f2087c98
parent 26688b86
......@@ -54,6 +54,23 @@ struct ArrayDataTraits<P*> {
}
};
template <typename T>
struct ArrayDataTraits<Array_Data<T>*> {
typedef ArrayPointer<T> StorageType;
typedef Array_Data<T>*& Ref;
typedef Array_Data<T>* const& ConstRef;
static size_t GetStorageSize(size_t num_elements) {
return 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.
......
[dist4]message_header // num_bytes
[u4]2 // num_fields
[u4]6 // name
[u4]0 // flags
[anchr]message_header
[dist4]method6_params // num_bytes
[u4]1 // num_fields
[dist8]param0_ptr // param0
[anchr]method6_params
[anchr]param0_ptr
[dist4]array_param // num_bytes
[u4]1 // num_elements
[dist8]element_ptr
[anchr]array_param
[anchr]element_ptr
[dist4]array_element // num_bytes
[u4]10 // num_elements
0 1 2 3 4 5 6 7 8 9
[anchr]array_element
[dist4]message_header // num_bytes
[u4]2 // num_fields
[u4]6 // name
[u4]0 // flags
[anchr]message_header
[dist4]method6_params // num_bytes
[u4]1 // num_fields
[dist8]param0_ptr // param0
[anchr]method6_params
[anchr]param0_ptr
[dist4]array_param // num_bytes
[u4]1 // num_elements
[dist8]element_ptr
[anchr]array_param
[anchr]element_ptr
[dist4]array_element // num_bytes: It is insufficient to store 12 elements.
[u4]12 // num_elements
0 1 2 3 4 5 6 7 8 9
[anchr]array_element
......@@ -32,6 +32,7 @@ interface ConformanceTestInterface {
Method3(bool[] param0);
Method4(StructC param0, uint8[] param1);
Method5(StructE param0, handle<data_pipe_producer> param1);
Method6(uint8[][] param0);
};
struct BasicStruct {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment