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

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
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 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 intptr_t str_len = str_obj.Length(); 1703 intptr_t str_len = str_obj.Length();
1704 intptr_t copy_len = (str_len > *length) ? *length : str_len; 1704 intptr_t copy_len = (str_len > *length) ? *length : str_len;
1705 for (intptr_t i = 0; i < copy_len; i++) { 1705 for (intptr_t i = 0; i < copy_len; i++) {
1706 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); 1706 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i));
1707 } 1707 }
1708 *length = copy_len; 1708 *length = copy_len;
1709 return Api::Success(isolate); 1709 return Api::Success(isolate);
1710 } 1710 }
1711 1711
1712 1712
1713 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str,
1714 intptr_t* size) {
1715 Isolate* isolate = Isolate::Current();
1716 DARTSCOPE(isolate);
1717 const String& str_obj = Api::UnwrapStringHandle(isolate, str);
1718 if (str_obj.IsNull()) {
1719 RETURN_TYPE_ERROR(isolate, str, String);
1720 }
1721 if (size == NULL) {
1722 RETURN_NULL_ERROR(size);
1723 }
1724 *size = (str_obj.Length() * str_obj.CharSize());
1725 return Api::Success(isolate);
1726 }
1727
1728
1729 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str,
1730 void* array,
1731 intptr_t length,
1732 void* peer,
1733 Dart_PeerFinalizer cback) {
1734 Isolate* isolate = Isolate::Current();
1735 DARTSCOPE(isolate);
1736 const String& str_obj = Api::UnwrapStringHandle(isolate, str);
1737 if (str_obj.IsExternal()) {
1738 return str; // String is already an external string.
1739 }
1740 if (str_obj.IsNull()) {
1741 RETURN_TYPE_ERROR(isolate, str, String);
1742 }
1743 if (array == NULL) {
1744 RETURN_NULL_ERROR(array);
1745 }
1746 intptr_t str_size = (str_obj.Length() * str_obj.CharSize());
1747 if ((length < str_size) || (length > String::kMaxElements)) {
1748 return Api::NewError("Dart_MakeExternalString "
1749 "expects argument length to be in the range"
1750 "[%"Pd"..%"Pd"].",
1751 str_size, String::kMaxElements);
1752 }
1753 return Api::NewHandle(isolate,
1754 str_obj.MakeExternal(array, length, peer, cback));
1755 }
1756
1757
1713 // --- Lists --- 1758 // --- Lists ---
1714 1759
1715 1760
1716 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { 1761 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) {
1717 if (obj.IsInstance()) { 1762 if (obj.IsInstance()) {
1718 const Instance& instance = Instance::Cast(obj); 1763 const Instance& instance = Instance::Cast(obj);
1719 const Type& type = 1764 const Type& type =
1720 Type::Handle(isolate, isolate->object_store()->list_interface()); 1765 Type::Handle(isolate, isolate->object_store()->list_interface());
1721 Error& malformed_type_error = Error::Handle(isolate); 1766 Error& malformed_type_error = Error::Handle(isolate);
1722 if (instance.IsInstanceOf(type, 1767 if (instance.IsInstanceOf(type,
(...skipping 2722 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

Powered by Google App Engine
This is Rietveld 408576698