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

Unified Diff: vm/dart_api_impl.cc

Issue 11360114: - Add functionality to morph a string into an external string (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 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
« no previous file with comments | « include/dart_api.h ('k') | vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/dart_api_impl.cc
===================================================================
--- vm/dart_api_impl.cc (revision 14977)
+++ vm/dart_api_impl.cc (working copy)
@@ -1709,6 +1709,51 @@
}
+DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str,
+ intptr_t* size) {
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ const String& str_obj = Api::UnwrapStringHandle(isolate, str);
+ if (str_obj.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, str, String);
+ }
+ if (size == NULL) {
+ RETURN_NULL_ERROR(size);
+ }
+ *size = (str_obj.Length() * str_obj.CharSize());
+ return Api::Success(isolate);
+}
+
+
+DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str,
+ void* array,
+ intptr_t length,
+ void* peer,
+ Dart_PeerFinalizer cback) {
+ Isolate* isolate = Isolate::Current();
+ DARTSCOPE(isolate);
+ const String& str_obj = Api::UnwrapStringHandle(isolate, str);
+ if (str_obj.IsExternal()) {
+ return str; // String is already an external string.
+ }
+ if (str_obj.IsNull()) {
+ RETURN_TYPE_ERROR(isolate, str, String);
+ }
+ if (array == NULL) {
+ RETURN_NULL_ERROR(array);
+ }
+ intptr_t str_size = (str_obj.Length() * str_obj.CharSize());
+ if ((length < str_size) || (length > String::kMaxElements)) {
+ return Api::NewError("Dart_MakeExternalString "
+ "expects argument length to be in the range"
+ "[%"Pd"..%"Pd"].",
+ str_size, String::kMaxElements);
+ }
+ return Api::NewHandle(isolate,
+ str_obj.MakeExternal(array, length, peer, cback));
+}
+
+
// --- Lists ---
« no previous file with comments | « include/dart_api.h ('k') | vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698