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

Unified Diff: runtime/lib/string.cc

Issue 12421002: Change VM's string-buffer patch to use a Uin16Array as backing buffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « no previous file | runtime/lib/string_buffer_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string.cc
diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc
index 3b5b633a9e9802114463d9bfd90b71426f257511..5b27b116997d49b8a4e66ba153543fd37136758f 100644
--- a/runtime/lib/string.cc
+++ b/runtime/lib/string.cc
@@ -49,7 +49,6 @@ DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) {
return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew);
}
-
DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) {
const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1));
@@ -197,4 +196,22 @@ DEFINE_NATIVE_ENTRY(Strings_concatAll, 1) {
return String::ConcatAll(strings);
}
+DEFINE_NATIVE_ENTRY(StringBuffer_createStringFromUint16Array, 2) {
+ GET_NON_NULL_NATIVE_ARGUMENT(Uint16Array, a, arguments->NativeArgAt(0));
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, smiLength, arguments->NativeArgAt(1));
+ intptr_t array_len = a.Length();
+ int32_t length = smiLength.Value();
+ if (length < 0 || length > array_len) {
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, smiLength);
+ Exceptions::ThrowByType(Exceptions::kRange, args);
+ }
+ // TODO(lrn): Pass parameter saying whether the data is Latin1, and
+ // use RawOneByteString::New/RawTwoByteString::New directly.
+ uint16_t* data_position = reinterpret_cast<uint16_t*>(
+ reinterpret_cast<char*>(a.raw()) +
+ Uint16Array::data_offset() - kHeapObjectTag);
+ return String::FromUTF16(data_position, length, Heap::kNew);
Vyacheslav Egorov (Google) 2013/03/05 14:44:32 This is not GC safe and is against VM guidelines.
+}
+
} // namespace dart
« no previous file with comments | « no previous file | runtime/lib/string_buffer_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698