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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10897014: Performance improvement for the Dart VM runtime method (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 | « runtime/vm/benchmark_test.cc ('k') | 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 11532)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -1528,22 +1528,48 @@
DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
void** peer) {
- Isolate* isolate = Isolate::Current();
- DARTSCOPE(isolate);
- const String& str = Api::UnwrapStringHandle(isolate, object);
- if (str.IsNull()) {
- RETURN_TYPE_ERROR(isolate, object, String);
+ 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 (!str.IsExternal()) {
+
+ // 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)) {
+ RETURN_TYPE_ERROR(Isolate::Current(), object, String);
+ } else {
return
- Api::NewError("%s expects argument 'object' to be an external String.",
- CURRENT_FUNC);
+ Api::NewError(
+ "%s expects argument 'object' to be an external String.",
+ CURRENT_FUNC);
}
- if (peer == NULL) {
- RETURN_NULL_ERROR(peer);
- }
- *peer = str.GetPeer();
- return Api::Success(isolate);
}
« no previous file with comments | « runtime/vm/benchmark_test.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698