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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 23118006: Simplify access to peer pointer for external strings. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | no next file » | 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 true_handle_ = Api::NewHandle(isolate, Bool::True().raw()); 233 true_handle_ = Api::NewHandle(isolate, Bool::True().raw());
234 234
235 ASSERT(false_handle_ == NULL); 235 ASSERT(false_handle_ == NULL);
236 false_handle_ = Api::NewHandle(isolate, Bool::False().raw()); 236 false_handle_ = Api::NewHandle(isolate, Bool::False().raw());
237 237
238 ASSERT(null_handle_ == NULL); 238 ASSERT(null_handle_ == NULL);
239 null_handle_ = Api::NewHandle(isolate, Object::null()); 239 null_handle_ = Api::NewHandle(isolate, Object::null());
240 } 240 }
241 241
242 242
243 #define GET_PEER(type, ctype, raw_obj, peer) \
244
245
246 #define EXTERNAL_PEER_HELPER(cid, raw_obj, peer) \
247 switch (cid) { \
248 case kExternalOneByteStringCid: { \
249 RawExternalOneByteString* raw_string = \
250 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr(); \
251 ExternalStringData<uint8_t>* data = raw_string->external_data_; \
252 *peer = data->peer(); \
253 return true; \
254 } \
255 case kExternalTwoByteStringCid: { \
256 RawExternalTwoByteString* raw_string = \
257 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); \
258 ExternalStringData<uint16_t>* data = raw_string->external_data_; \
259 *peer = data->peer(); \
260 return true; \
261 } \
262 } \
263 return false; \
264
265
266 bool Api::ExternalStringGetPeerHelper(Dart_NativeArguments args,
267 int arg_index,
268 void** peer) {
269 NoGCScope no_gc_scope;
270 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
271 RawObject* raw_obj = arguments->NativeArgAt(arg_index);
272 intptr_t cid = raw_obj->GetClassId();
273 EXTERNAL_PEER_HELPER(cid, raw_obj, peer);
274 }
275
276
243 bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) { 277 bool Api::ExternalStringGetPeerHelper(Dart_Handle object, void** peer) {
244 NoGCScope no_gc_scope; 278 NoGCScope no_gc_scope;
245 RawObject* raw_obj = Api::UnwrapHandle(object); 279 RawObject* raw_obj = Api::UnwrapHandle(object);
246 switch (Api::ClassId(object)) { 280 EXTERNAL_PEER_HELPER(Api::ClassId(object), raw_obj, peer);
247 case kExternalOneByteStringCid: {
248 RawExternalOneByteString* raw_string =
249 reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr();
250 ExternalStringData<uint8_t>* data = raw_string->external_data_;
251 *peer = data->peer();
252 return true;
253 }
254 case kExternalTwoByteStringCid: {
255 RawExternalTwoByteString* raw_string =
256 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr();
257 ExternalStringData<uint16_t>* data = raw_string->external_data_;
258 *peer = data->peer();
259 return true;
260 }
261 }
262 return false;
263 } 281 }
264 282
265 283
266 void Api::SetWeakHandleReturnValue(NativeArguments* args, 284 void Api::SetWeakHandleReturnValue(NativeArguments* args,
267 Dart_WeakPersistentHandle retval) { 285 Dart_WeakPersistentHandle retval) {
268 args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw()); 286 args->SetReturnUnsafe(Api::UnwrapAsWeakPersistentHandle(retval)->raw());
269 } 287 }
270 288
271 289
272 // --- Handles --- 290 // --- Handles ---
(...skipping 3406 matching lines...) Expand 10 before | Expand all | Expand 10 after
3679 return Api::Success(); 3697 return Api::Success();
3680 } 3698 }
3681 3699
3682 3700
3683 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, 3701 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args,
3684 int arg_index, 3702 int arg_index,
3685 void** peer) { 3703 void** peer) {
3686 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3704 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
3687 Isolate* isolate = arguments->isolate(); 3705 Isolate* isolate = arguments->isolate();
3688 CHECK_ISOLATE(isolate); 3706 CHECK_ISOLATE(isolate);
3707 if (Api::ExternalStringGetPeerHelper(args, arg_index, peer)) {
3708 return Api::Success();
3709 }
3710 *peer = NULL;
3689 ReusableObjectHandleScope reused_obj_handle(isolate); 3711 ReusableObjectHandleScope reused_obj_handle(isolate);
3690 Object& obj = reused_obj_handle.Handle(); 3712 Object& obj = reused_obj_handle.Handle();
3691 obj = arguments->NativeArgAt(arg_index); 3713 obj = arguments->NativeArgAt(arg_index);
3692 intptr_t cid = obj.GetClassId(); 3714 if (RawObject::IsStringClassId(obj.GetClassId())) {
3693 if (RawObject::IsExternalStringClassId(cid)) {
3694 const String& str = String::Cast(obj);
3695 *peer = str.GetPeer();
3696 ASSERT(*peer != NULL);
3697 return Api::Success();
3698 }
3699 *peer = NULL;
3700 if (RawObject::IsStringClassId(cid)) {
3701 return Api::NewHandle(isolate, obj.raw()); 3715 return Api::NewHandle(isolate, obj.raw());
3702 } 3716 }
3703 return Api::NewError("%s expects argument to be of" 3717 return Api::NewError("%s expects argument to be of"
3704 " type String.", CURRENT_FUNC); 3718 " type String.", CURRENT_FUNC);
3705 } 3719 }
3706 3720
3707 3721
3708 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 3722 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
3709 Dart_Handle retval) { 3723 Dart_Handle retval) {
3710 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 3724 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
4235 } 4249 }
4236 { 4250 {
4237 NoGCScope no_gc; 4251 NoGCScope no_gc;
4238 RawObject* raw_obj = obj.raw(); 4252 RawObject* raw_obj = obj.raw();
4239 isolate->heap()->SetPeer(raw_obj, peer); 4253 isolate->heap()->SetPeer(raw_obj, peer);
4240 } 4254 }
4241 return Api::Success(); 4255 return Api::Success();
4242 } 4256 }
4243 4257
4244 } // namespace dart 4258 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698