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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 8383029: Implement external strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fully displace external string metadata Created 9 years, 1 month 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
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 06e63a2950a4dd879cc0a1d6715e6901c3b92f62..da2340bebc11caa779afcb57dc127b0271d62766 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -791,11 +791,47 @@ DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
}
+DART_EXPORT Dart_Handle Dart_NewExternalString8(uint8_t* codepoints,
+ intptr_t length,
+ void* peer,
+ Dart_PeerFinalizer callback) {
+ Zone zone; // Setup a VM zone as we are creating some handles.
+ HandleScope scope; // Setup a VM handle scope.
siva 2011/11/18 23:26:09 When you sync up these two lines will be replaced
cshapiro 2011/11/19 01:08:29 Thanks for pointing this out. I discovered the ch
+ const String& obj =
+ String::Handle(String::NewExternal(codepoints, length, peer, callback));
+ return Api::NewLocalHandle(obj);
+}
+
+
+DART_EXPORT Dart_Handle Dart_NewExternalString16(uint16_t* codepoints,
+ intptr_t length,
+ void* peer,
+ Dart_PeerFinalizer callback) {
+ Zone zone; // Setup a VM zone as we are creating some handles.
+ HandleScope scope; // Setup a VM handle scope.
+ const String& obj =
+ String::Handle(String::NewExternal(codepoints, length, peer, callback));
+ return Api::NewLocalHandle(obj);
+}
+
+
+DART_EXPORT Dart_Handle Dart_NewExternalString32(uint32_t* codepoints,
+ intptr_t length,
+ void* peer,
+ Dart_PeerFinalizer callback) {
+ Zone zone; // Setup a VM zone as we are creating some handles.
+ HandleScope scope; // Setup a VM handle scope.
+ const String& obj =
+ String::Handle(String::NewExternal(codepoints, length, peer, callback));
+ return Api::NewLocalHandle(obj);
+}
+
+
DART_EXPORT bool Dart_IsString8(Dart_Handle object) {
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
const Object& obj = Object::Handle(Api::UnwrapHandle(object));
- return obj.IsOneByteString();
+ return obj.IsOneByteString() || obj.IsExternalOneByteString();
}
@@ -803,7 +839,8 @@ DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
const Object& obj = Object::Handle(Api::UnwrapHandle(object));
- return obj.IsOneByteString() || obj.IsTwoByteString();
+ return (obj.IsOneByteString() || obj.IsExternalOneByteString() ||
+ obj.IsTwoByteString() || obj.IsExternalOneByteString());
Ivan Posva 2011/11/18 19:36:44 obj.IsExternalOneByteString() -> obj.IsExternalTwo
cshapiro 2011/11/19 01:08:29 Fixed. I could not find any tests for this functi
}
@@ -813,16 +850,18 @@ DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
const Object& obj = Object::Handle(Api::UnwrapHandle(str));
- if (obj.IsOneByteString()) {
- OneByteString& string_obj = OneByteString::Handle();
+ if (obj.IsString()) {
+ String& string_obj = String::Handle();
siva 2011/11/18 23:26:09 If you manage to get your change in before Todd th
string_obj ^= obj.raw();
- intptr_t str_len = string_obj.Length();
- intptr_t copy_len = (str_len > *length) ? *length : str_len;
- for (intptr_t i = 0; i < copy_len; i++) {
- codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
+ if (string_obj.CharSize() == String::kOneByteChar) {
+ intptr_t str_len = string_obj.Length();
+ intptr_t copy_len = (str_len > *length) ? *length : str_len;
+ for (intptr_t i = 0; i < copy_len; i++) {
+ codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
+ }
+ *length= copy_len;
+ return Api::Success();
}
- *length= copy_len;
- return Api::Success();
}
return Api::Error(obj.IsString()
? "Object is not a String8"
@@ -836,16 +875,18 @@ DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str,
Zone zone; // Setup a VM zone as we are creating some handles.
HandleScope scope; // Setup a VM handle scope.
const Object& obj = Object::Handle(Api::UnwrapHandle(str));
- if (obj.IsOneByteString() || obj.IsTwoByteString()) {
+ if (obj.IsString()) {
String& string_obj = String::Handle();
string_obj ^= obj.raw();
- intptr_t str_len = string_obj.Length();
- intptr_t copy_len = (str_len > *length) ? *length : str_len;
- for (intptr_t i = 0; i < copy_len; i++) {
- codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i));
+ if (string_obj.CharSize() <= String::kTwoByteChar) {
+ intptr_t str_len = string_obj.Length();
+ intptr_t copy_len = (str_len > *length) ? *length : str_len;
+ for (intptr_t i = 0; i < copy_len; i++) {
+ codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i));
+ }
+ *length = copy_len;
+ return Api::Success();
}
- *length = copy_len;
- return Api::Success();
}
return Api::Error(obj.IsString()
? "Object is not a String16"

Powered by Google App Engine
This is Rietveld 408576698