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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10891036: Reworked previous CL (ExternalStringGetPeer speed up) to avoid the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/raw_object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 11534)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -1526,43 +1526,50 @@
}
+bool ExternalStringGetPeerHelper(Dart_Handle object, void** peer) {
+ NoGCScope no_gc_scope;
+ RawObject* raw_obj = Api::UnwrapHandle(object);
+ switch (Api::ClassId(object)) {
+ case kExternalOneByteStringCid: {
+ RawExternalOneByteString* raw_string =
+ reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr();
+ ExternalStringData<uint8_t>* data = raw_string->external_data_;
+ *peer = data->peer();
+ return true;
+ }
+ case kExternalTwoByteStringCid: {
+ RawExternalTwoByteString* raw_string =
+ reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr();
+ ExternalStringData<uint16_t>* data = raw_string->external_data_;
+ *peer = data->peer();
+ return true;
+ }
+ case kExternalFourByteStringCid: {
+ RawExternalFourByteString* raw_string =
+ reinterpret_cast<RawExternalFourByteString*>(raw_obj)->ptr();
+ ExternalStringData<uint32_t>* data = raw_string->external_data_;
+ *peer = data->peer();
+ return true;
+ }
+ }
+ return false;
+}
+
+
DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
void** peer) {
- intptr_t class_id = Api::ClassId(object);
if (peer == NULL) {
RETURN_NULL_ERROR(peer);
- } else {
- NoGCScope no_gc_scope;
- RawObject* raw_obj = Api::UnwrapHandle(object);
- switch (class_id) {
- case kExternalOneByteStringCid: {
- RawExternalOneByteString* raw_string =
- reinterpret_cast<RawExternalOneByteString*>(raw_obj)->ptr();
- ExternalStringData<uint8_t>* data = raw_string->external_data_;
- *peer = data->peer();
- return Api::Success(Isolate::Current());
- }
- case kExternalTwoByteStringCid: {
- RawExternalTwoByteString* raw_string =
- reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr();
- ExternalStringData<uint16_t>* data = raw_string->external_data_;
- *peer = data->peer();
- return Api::Success(Isolate::Current());
- }
- case kExternalFourByteStringCid: {
- RawExternalFourByteString* raw_string =
- reinterpret_cast<RawExternalFourByteString*>(raw_obj)->ptr();
- ExternalStringData<uint32_t>* data = raw_string->external_data_;
- *peer = data->peer();
- return Api::Success(Isolate::Current());
- }
- }
}
+ if (ExternalStringGetPeerHelper(object, peer)) {
+ return Api::Success(Isolate::Current());
+ }
+
// It's not an external string, return appropriate error.
// Note: this is invoked outside of the NoGCScope'd block above, since
// error messages allocate new handles.
- if (!RawObject::IsStringClassId(class_id)) {
+ if (!RawObject::IsStringClassId(Api::ClassId(object))) {
RETURN_TYPE_ERROR(Isolate::Current(), object, String);
} else {
return
« no previous file with comments | « no previous file | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698