Chromium Code Reviews| Index: runtime/lib/byte_array.cc |
| diff --git a/runtime/lib/byte_array.cc b/runtime/lib/byte_array.cc |
| index 2f61030e7a0b75145873cab828df04bebaf4c3d1..3c8e4d76a5834d75ae140a41cd2e738334ec1b26 100644 |
| --- a/runtime/lib/byte_array.cc |
| +++ b/runtime/lib/byte_array.cc |
| @@ -42,6 +42,11 @@ static void LengthCheck(intptr_t len, intptr_t max) { |
| } |
| } |
| +#define EXTERNAL_ALIGNMENT 16 |
|
cshapiro
2012/11/29 21:28:17
Macros like this are strongly discouraged by the s
Cutch
2012/11/29 23:53:17
Done.
|
| + |
| +void FinalizeExternalBytes(void* ptr) { |
|
cshapiro
2012/11/29 21:28:17
Any reason for this routine? Why not just pass OS
Cutch
2012/11/29 23:53:17
Done.
|
| + OS::AlignedFree(ptr); |
| +} |
| #define GETTER_ARGUMENTS(ArrayT, ValueT) \ |
| GET_NATIVE_ARGUMENT(ArrayT, array, arguments->NativeArgAt(0)); \ |
| @@ -285,6 +290,18 @@ DEFINE_NATIVE_ENTRY(Int8Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Int8Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Int8Array::kMaxElements); |
| + void* bytes = OS::AlignedAllocate(len*sizeof(int8_t), EXTERNAL_ALIGNMENT); |
|
cshapiro
2012/11/29 21:28:17
I think there are some opportunities for improveme
Cutch
2012/11/29 23:53:17
Done.
|
| + return ExternalInt8Array::New(reinterpret_cast<int8_t*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Int8Array_getIndexed, 2) { |
| GETTER(Int8Array, Smi, int8_t); |
| } |
| @@ -305,6 +322,19 @@ DEFINE_NATIVE_ENTRY(Uint8Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Uint8Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Uint8Array::kMaxElements); |
| + void* bytes = OS::AlignedAllocate(len * sizeof(uint8_t), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalUint8Array::New(reinterpret_cast<uint8_t*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Uint8Array_getIndexed, 2) { |
| GETTER(Uint8Array, Smi, uint8_t); |
| } |
| @@ -325,6 +355,19 @@ DEFINE_NATIVE_ENTRY(Int16Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Int16Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Int16Array::kMaxElements); |
| + void* bytes = OS::AlignedAllocate(len * sizeof(int16_t), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalInt16Array::New(reinterpret_cast<int16_t*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Int16Array_getIndexed, 2) { |
| GETTER(Int16Array, Smi, int16_t); |
| } |
| @@ -345,6 +388,19 @@ DEFINE_NATIVE_ENTRY(Uint16Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Uint16Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Uint16Array::kMaxElements); |
| + void* bytes = OS::AlignedAllocate(len * sizeof(uint16_t), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalUint16Array::New(reinterpret_cast<uint16_t*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Uint16Array_getIndexed, 2) { |
| GETTER(Uint16Array, Smi, uint16_t); |
| } |
| @@ -365,6 +421,19 @@ DEFINE_NATIVE_ENTRY(Int32Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Int32Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Int32Array::kMaxElements); |
| + void* bytes = OS::AlignedAllocate(len * sizeof(int32_t), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalInt32Array::New(reinterpret_cast<int32_t*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Int32Array_getIndexed, 2) { |
| GETTER(Int32Array, Integer, int32_t); |
| } |
| @@ -385,6 +454,19 @@ DEFINE_NATIVE_ENTRY(Uint32Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Uint32Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Uint32Array::kMaxElements); |
| + void* bytes = OS::AlignedAllocate(len * sizeof(uint32_t), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalUint32Array::New(reinterpret_cast<uint32_t*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Uint32Array_getIndexed, 2) { |
| GETTER(Uint32Array, Integer, uint32_t); |
| } |
| @@ -405,6 +487,19 @@ DEFINE_NATIVE_ENTRY(Int64Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Int64Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Int64Array::kMaxElements); |
| + void* bytes = OS::AlignedAllocate(len * sizeof(int64_t), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalInt64Array::New(reinterpret_cast<int64_t*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Int64Array_getIndexed, 2) { |
| GETTER(Int64Array, Integer, int64_t); |
| } |
| @@ -425,6 +520,19 @@ DEFINE_NATIVE_ENTRY(Uint64Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Uint64Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Uint64Array::kMaxElements); |
| + void* bytes = OS::AlignedAllocate(len * sizeof(uint64_t), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalUint64Array::New(reinterpret_cast<uint64_t*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Uint64Array_getIndexed, 2) { |
| GETTER_UINT64(Uint64Array); |
| } |
| @@ -445,6 +553,20 @@ DEFINE_NATIVE_ENTRY(Float32Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Float32Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Float32Array::kMaxElements); |
| + float foo; // quiet cpplint. |
|
cshapiro
2012/11/29 21:28:17
cpplint does not want you using sizeof(<typename>)
Cutch
2012/11/29 23:53:17
Done.
|
| + void* bytes = OS::AlignedAllocate(len * sizeof(foo), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalFloat32Array::New(reinterpret_cast<float*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Float32Array_getIndexed, 2) { |
| GETTER(Float32Array, Double, float); |
| } |
| @@ -465,6 +587,20 @@ DEFINE_NATIVE_ENTRY(Float64Array_new, 1) { |
| } |
| +DEFINE_NATIVE_ENTRY(Float64Array_newTransferrable, 1) { |
| + GET_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); |
| + intptr_t len = length.Value(); |
| + LengthCheck(len, Float64Array::kMaxElements); |
| + double foo; // quiet cpplint. |
| + void* bytes = OS::AlignedAllocate(len * sizeof(foo), |
| + EXTERNAL_ALIGNMENT); |
| + return ExternalFloat64Array::New(reinterpret_cast<double*>(bytes), |
| + len, |
| + bytes, |
| + FinalizeExternalBytes); |
| +} |
| + |
| + |
| DEFINE_NATIVE_ENTRY(Float64Array_getIndexed, 2) { |
| GETTER(Float64Array, Double, double); |
| } |