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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/dart_api.h ('k') | vm/dart_api_impl_test.cc » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 intptr_t str_len = str_obj.Length(); 1702 intptr_t str_len = str_obj.Length();
1703 intptr_t copy_len = (str_len > *length) ? *length : str_len; 1703 intptr_t copy_len = (str_len > *length) ? *length : str_len;
1704 for (intptr_t i = 0; i < copy_len; i++) { 1704 for (intptr_t i = 0; i < copy_len; i++) {
1705 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); 1705 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i));
1706 } 1706 }
1707 *length = copy_len; 1707 *length = copy_len;
1708 return Api::Success(isolate); 1708 return Api::Success(isolate);
1709 } 1709 }
1710 1710
1711 1711
1712 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str,
1713 intptr_t* size) {
1714 Isolate* isolate = Isolate::Current();
1715 DARTSCOPE(isolate);
1716 const String& str_obj = Api::UnwrapStringHandle(isolate, str);
1717 if (str_obj.IsNull()) {
1718 RETURN_TYPE_ERROR(isolate, str, String);
1719 }
1720 if (size == NULL) {
1721 RETURN_NULL_ERROR(size);
1722 }
1723 *size = (str_obj.Length() * str_obj.CharSize());
1724 return Api::Success(isolate);
1725 }
1726
1727
1728 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str,
1729 void* array,
1730 intptr_t length,
1731 void* peer,
1732 Dart_PeerFinalizer cback) {
1733 Isolate* isolate = Isolate::Current();
1734 DARTSCOPE(isolate);
1735 const String& str_obj = Api::UnwrapStringHandle(isolate, str);
1736 if (str_obj.IsExternal()) {
1737 return str; // String is already an external string.
1738 }
1739 if (str_obj.IsNull()) {
1740 RETURN_TYPE_ERROR(isolate, str, String);
1741 }
1742 if (array == NULL) {
1743 RETURN_NULL_ERROR(array);
1744 }
1745 intptr_t str_size = (str_obj.Length() * str_obj.CharSize());
1746 if ((length < str_size) || (length > String::kMaxElements)) {
1747 return Api::NewError("Dart_MakeExternalString "
1748 "expects argument length to be in the range"
1749 "[%"Pd"..%"Pd"].",
1750 str_size, String::kMaxElements);
1751 }
1752 return Api::NewHandle(isolate,
1753 str_obj.MakeExternal(array, length, peer, cback));
1754 }
1755
1756
1712 // --- Lists --- 1757 // --- Lists ---
1713 1758
1714 1759
1715 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { 1760 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) {
1716 if (obj.IsInstance()) { 1761 if (obj.IsInstance()) {
1717 const Instance& instance = Instance::Cast(obj); 1762 const Instance& instance = Instance::Cast(obj);
1718 const Type& type = 1763 const Type& type =
1719 Type::Handle(isolate, isolate->object_store()->list_interface()); 1764 Type::Handle(isolate, isolate->object_store()->list_interface());
1720 Error& malformed_type_error = Error::Handle(isolate); 1765 Error& malformed_type_error = Error::Handle(isolate);
1721 if (instance.IsInstanceOf(type, 1766 if (instance.IsInstanceOf(type,
(...skipping 2723 matching lines...) Expand 10 before | Expand all | Expand 10 after
4445 } 4490 }
4446 { 4491 {
4447 NoGCScope no_gc; 4492 NoGCScope no_gc;
4448 RawObject* raw_obj = obj.raw(); 4493 RawObject* raw_obj = obj.raw();
4449 isolate->heap()->SetPeer(raw_obj, peer); 4494 isolate->heap()->SetPeer(raw_obj, peer);
4450 } 4495 }
4451 return Api::Success(isolate); 4496 return Api::Success(isolate);
4452 } 4497 }
4453 4498
4454 } // namespace dart 4499 } // namespace dart
OLDNEW
« 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