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

Side by Side Diff: runtime/lib/typed_data.cc

Issue 1782003002: Simplify the VM's typed_data constructors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: added comment Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/lib/typed_data.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/native_entry.h" 10 #include "vm/native_entry.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 156 }
157 UNREACHABLE(); 157 UNREACHABLE();
158 return Bool::False().raw(); 158 return Bool::False().raw();
159 } 159 }
160 160
161 161
162 // We check the length parameter against a possible maximum length for the 162 // We check the length parameter against a possible maximum length for the
163 // array based on available physical addressable memory on the system. The 163 // array based on available physical addressable memory on the system. The
164 // maximum possible length is a scaled value of kSmiMax which is set up based 164 // maximum possible length is a scaled value of kSmiMax which is set up based
165 // on whether the underlying architecture is 32-bit or 64-bit. 165 // on whether the underlying architecture is 32-bit or 64-bit.
166 // Argument 0 is type arguments and is ignored.
166 #define TYPED_DATA_NEW(name) \ 167 #define TYPED_DATA_NEW(name) \
167 DEFINE_NATIVE_ENTRY(TypedData_##name##_new, 1) { \ 168 DEFINE_NATIVE_ENTRY(TypedData_##name##_new, 2) { \
168 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); \ 169 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1)); \
169 intptr_t cid = kTypedData##name##Cid; \ 170 intptr_t cid = kTypedData##name##Cid; \
170 intptr_t len = length.Value(); \ 171 intptr_t len = length.Value(); \
171 intptr_t max = TypedData::MaxElements(cid); \ 172 intptr_t max = TypedData::MaxElements(cid); \
172 LengthCheck(len, max); \ 173 LengthCheck(len, max); \
173 return TypedData::New(cid, len); \ 174 return TypedData::New(cid, len); \
174 } \ 175 } \
175 176
176 177
177 // We check the length parameter against a possible maximum length for the 178 // We check the length parameter against a possible maximum length for the
178 // array based on available physical addressable memory on the system. The 179 // array based on available physical addressable memory on the system. The
179 // maximum possible length is a scaled value of kSmiMax which is set up based 180 // maximum possible length is a scaled value of kSmiMax which is set up based
180 // on whether the underlying architecture is 32-bit or 64-bit. 181 // on whether the underlying architecture is 32-bit or 64-bit.
182 // Argument 0 is type arguments and is ignored.
181 #define EXT_TYPED_DATA_NEW(name) \ 183 #define EXT_TYPED_DATA_NEW(name) \
182 DEFINE_NATIVE_ENTRY(ExternalTypedData_##name##_new, 1) { \ 184 DEFINE_NATIVE_ENTRY(ExternalTypedData_##name##_new, 2) { \
183 const int kAlignment = 16; \ 185 const int kAlignment = 16; \
184 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(0)); \ 186 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1)); \
185 intptr_t cid = kExternalTypedData##name##Cid; \ 187 intptr_t cid = kExternalTypedData##name##Cid; \
186 intptr_t len = length.Value(); \ 188 intptr_t len = length.Value(); \
187 intptr_t max = ExternalTypedData::MaxElements(cid); \ 189 intptr_t max = ExternalTypedData::MaxElements(cid); \
188 LengthCheck(len, max); \ 190 LengthCheck(len, max); \
189 intptr_t len_bytes = len * ExternalTypedData::ElementSizeInBytes(cid); \ 191 intptr_t len_bytes = len * ExternalTypedData::ElementSizeInBytes(cid); \
190 uint8_t* data = OS::AllocateAlignedArray<uint8_t>(len_bytes, kAlignment); \ 192 uint8_t* data = OS::AllocateAlignedArray<uint8_t>(len_bytes, kAlignment); \
191 const ExternalTypedData& obj = \ 193 const ExternalTypedData& obj = \
192 ExternalTypedData::Handle(ExternalTypedData::New(cid, data, len)); \ 194 ExternalTypedData::Handle(ExternalTypedData::New(cid, data, len)); \
193 obj.AddFinalizer(data, PeerFinalizer); \ 195 obj.AddFinalizer(data, PeerFinalizer); \
194 return obj.raw(); \ 196 return obj.raw(); \
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 value = bit_cast<double>( 392 value = bit_cast<double>(
391 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value))); 393 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value)));
392 } else { 394 } else {
393 value = bit_cast<double>( 395 value = bit_cast<double>(
394 Utils::HostToBigEndian64(bit_cast<uint64_t>(value))); 396 Utils::HostToBigEndian64(bit_cast<uint64_t>(value)));
395 } 397 }
396 return Double::New(value); 398 return Double::New(value);
397 } 399 }
398 400
399 } // namespace dart 401 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/typed_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698