Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 return Smi::New(array.Length()); | 71 return Smi::New(array.Length()); |
| 72 } | 72 } |
| 73 const String& error = String::Handle(String::NewFormatted( | 73 const String& error = String::Handle(String::NewFormatted( |
| 74 "Expected a TypedData object but found %s", instance.ToCString())); | 74 "Expected a TypedData object but found %s", instance.ToCString())); |
| 75 const Array& args = Array::Handle(Array::New(1)); | 75 const Array& args = Array::Handle(Array::New(1)); |
| 76 args.SetAt(0, error); | 76 args.SetAt(0, error); |
| 77 Exceptions::ThrowByType(Exceptions::kArgument, args); | 77 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 78 return Integer::null(); | 78 return Integer::null(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 | 81 template <typename DstType, typename SrcType> |
| 82 #define COPY_DATA(type, dst, src) \ | 82 static RawBool* CopyData(const Instance& dst, const Instance& src, |
| 83 const type& dst_array = type::Cast(dst); \ | 83 const Smi& dst_start, const Smi& src_start, |
| 84 const type& src_array = type::Cast(src); \ | 84 const Smi& length) { |
| 85 intptr_t element_size_in_bytes = dst_array.ElementSizeInBytes(); \ | 85 const DstType& dst_array = DstType::Cast(dst); |
| 86 intptr_t length_in_bytes = length.Value() * element_size_in_bytes; \ | 86 const SrcType& src_array = SrcType::Cast(src); |
| 87 intptr_t src_offset_in_bytes = src_start.Value() * element_size_in_bytes; \ | 87 intptr_t element_size_in_bytes = dst_array.ElementSizeInBytes(); |
| 88 intptr_t dst_offset_in_bytes = dst_start.Value() * element_size_in_bytes; \ | 88 intptr_t dst_offset_in_bytes = dst_start.Value() * element_size_in_bytes; |
| 89 SetRangeCheck(src_offset_in_bytes, \ | 89 intptr_t src_offset_in_bytes = src_start.Value() * element_size_in_bytes; |
| 90 length_in_bytes, \ | 90 intptr_t length_in_bytes = length.Value() * element_size_in_bytes; |
| 91 src_array.LengthInBytes(), \ | 91 if (dst_array.ElementType() == src_array.ElementType()) { |
|
Anders Johnsen
2013/04/18 11:00:43
DBC: !=
kustermann
2013/04/18 13:57:57
That was really stupid of me.
| |
| 92 element_size_in_bytes); \ | 92 return Bool::False().raw(); |
| 93 SetRangeCheck(dst_offset_in_bytes, \ | 93 } |
| 94 length_in_bytes, \ | 94 SetRangeCheck(src_offset_in_bytes, |
| 95 dst_array.LengthInBytes(), \ | 95 length_in_bytes, |
| 96 element_size_in_bytes); \ | 96 src_array.LengthInBytes(), |
| 97 type::Copy(dst_array, dst_offset_in_bytes, \ | 97 element_size_in_bytes); |
| 98 src_array, src_offset_in_bytes, \ | 98 SetRangeCheck(dst_offset_in_bytes, |
| 99 length_in_bytes); | 99 length_in_bytes, |
| 100 dst_array.LengthInBytes(), | |
| 101 element_size_in_bytes); | |
| 102 { | |
| 103 NoGCScope no_gc; | |
|
Vyacheslav Egorov (Google)
2013/04/17 11:41:56
If TypedData and ExternalTypedData had a base clas
kustermann
2013/04/18 13:57:57
I agree that a base class would solve the code dup
| |
| 104 if (length_in_bytes > 0) { | |
| 105 memmove(dst_array.DataAddr(dst_offset_in_bytes), | |
| 106 src_array.DataAddr(src_offset_in_bytes), | |
| 107 length_in_bytes); | |
| 108 } | |
| 109 return Bool::True().raw(); | |
| 110 } | |
| 111 } | |
| 100 | 112 |
| 101 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) { | 113 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) { |
| 102 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0)); | 114 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0)); |
| 103 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); | 115 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); |
| 104 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); | 116 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); |
| 105 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3)); | 117 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3)); |
| 106 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); | 118 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); |
| 107 | 119 |
| 108 if (length.Value() < 0) { | 120 if (length.Value() < 0) { |
| 109 const String& error = String::Handle(String::NewFormatted( | 121 const String& error = String::Handle(String::NewFormatted( |
| 110 "length (%"Pd") must be non-negative", length.Value())); | 122 "length (%"Pd") must be non-negative", length.Value())); |
| 111 const Array& args = Array::Handle(Array::New(1)); | 123 const Array& args = Array::Handle(Array::New(1)); |
| 112 args.SetAt(0, error); | 124 args.SetAt(0, error); |
| 113 Exceptions::ThrowByType(Exceptions::kArgument, args); | 125 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 114 } | 126 } |
| 115 if ((dst.IsTypedData() || dst.IsExternalTypedData()) && | 127 if (dst.IsTypedData()) { |
| 116 (dst.clazz() == src.clazz())) { | 128 if (src.IsTypedData()) { |
| 117 if (dst.IsTypedData()) { | 129 return CopyData<TypedData, TypedData>( |
| 118 ASSERT(src.IsTypedData()); | 130 dst, src, dst_start, src_start, length); |
| 119 COPY_DATA(TypedData, dst, src); | 131 } else if (src.IsExternalTypedData()) { |
| 120 } else { | 132 return CopyData<TypedData, ExternalTypedData>( |
| 121 ASSERT(src.IsExternalTypedData()); | 133 dst, src, dst_start, src_start, length); |
| 122 ASSERT(dst.IsExternalTypedData()); | |
| 123 COPY_DATA(ExternalTypedData, dst, src); | |
| 124 } | 134 } |
| 125 return Bool::True().raw(); | 135 } else if (dst.IsExternalTypedData()) { |
| 136 if (src.IsTypedData()) { | |
| 137 return CopyData<ExternalTypedData, TypedData>( | |
| 138 dst, src, dst_start, src_start, length); | |
| 139 } else if (src.IsExternalTypedData()) { | |
| 140 return CopyData<ExternalTypedData, ExternalTypedData>( | |
| 141 dst, src, dst_start, src_start, length); | |
| 142 } | |
| 126 } | 143 } |
| 127 return Bool::False().raw(); | 144 return Bool::False().raw(); |
| 128 } | 145 } |
| 129 | 146 |
| 130 | 147 |
| 131 // We check the length parameter against a possible maximum length for the | 148 // We check the length parameter against a possible maximum length for the |
| 132 // array based on available physical addressable memory on the system. The | 149 // array based on available physical addressable memory on the system. The |
| 133 // maximum possible length is a scaled value of kSmiMax which is set up based | 150 // maximum possible length is a scaled value of kSmiMax which is set up based |
| 134 // on whether the underlying architecture is 32-bit or 64-bit. | 151 // on whether the underlying architecture is 32-bit or 64-bit. |
| 135 #define TYPED_DATA_NEW(name) \ | 152 #define TYPED_DATA_NEW(name) \ |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 TYPED_DATA_NATIVES(Uint16Array, GetUint16, SetUint16, Smi, Value) | 318 TYPED_DATA_NATIVES(Uint16Array, GetUint16, SetUint16, Smi, Value) |
| 302 TYPED_DATA_NATIVES(Int32Array, GetInt32, SetInt32, Integer, AsInt64Value) | 319 TYPED_DATA_NATIVES(Int32Array, GetInt32, SetInt32, Integer, AsInt64Value) |
| 303 TYPED_DATA_NATIVES(Uint32Array, GetUint32, SetUint32, Integer, AsInt64Value) | 320 TYPED_DATA_NATIVES(Uint32Array, GetUint32, SetUint32, Integer, AsInt64Value) |
| 304 TYPED_DATA_NATIVES(Int64Array, GetInt64, SetInt64, Integer, AsInt64Value) | 321 TYPED_DATA_NATIVES(Int64Array, GetInt64, SetInt64, Integer, AsInt64Value) |
| 305 TYPED_DATA_UINT64_NATIVES(Uint64Array, GetUint64, SetUint64, Integer) | 322 TYPED_DATA_UINT64_NATIVES(Uint64Array, GetUint64, SetUint64, Integer) |
| 306 TYPED_DATA_NATIVES(Float32Array, GetFloat32, SetFloat32, Double, value) | 323 TYPED_DATA_NATIVES(Float32Array, GetFloat32, SetFloat32, Double, value) |
| 307 TYPED_DATA_NATIVES(Float64Array, GetFloat64, SetFloat64, Double, value) | 324 TYPED_DATA_NATIVES(Float64Array, GetFloat64, SetFloat64, Double, value) |
| 308 TYPED_DATA_NATIVES(Float32x4Array, GetFloat32x4, SetFloat32x4, Float32x4, value) | 325 TYPED_DATA_NATIVES(Float32x4Array, GetFloat32x4, SetFloat32x4, Float32x4, value) |
| 309 | 326 |
| 310 } // namespace dart | 327 } // namespace dart |
| OLD | NEW |