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

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: Made Uint16Array.ByteAddr public and used that to get address of code units. Created 7 years, 9 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 | « runtime/lib/core_patch.dart ('k') | 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..48b81e96fb72e94bebc075241071b3fb7dc97098 100644
--- a/runtime/lib/string.cc
+++ b/runtime/lib/string.cc
@@ -197,4 +197,27 @@ DEFINE_NATIVE_ENTRY(Strings_concatAll, 1) {
return String::ConcatAll(strings);
}
+
+DEFINE_NATIVE_ENTRY(StringBuffer_createStringFromUint16Array, 3) {
+ GET_NON_NULL_NATIVE_ARGUMENT(Uint16Array, codeUnits,
+ arguments->NativeArgAt(0));
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(1));
+ GET_NON_NULL_NATIVE_ARGUMENT(Bool, isLatin1, arguments->NativeArgAt(2));
+ intptr_t array_length = codeUnits.Length();
+ intptr_t length_value = length.Value();
+ if (length_value < 0 || length_value > array_length) {
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, length);
+ Exceptions::ThrowByType(Exceptions::kRange, args);
+ }
+ const String& result = isLatin1.value()
+ ? String::Handle(OneByteString::New(length_value, Heap::kNew))
+ : String::Handle(TwoByteString::New(length_value, Heap::kNew));
+ NoGCScope no_gc;
+
+ uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.ByteAddr(0));
+ String::Copy(result, 0, data_position, length_value);
+ return result.raw();
+}
+
} // namespace dart
« no previous file with comments | « runtime/lib/core_patch.dart ('k') | runtime/lib/string_buffer_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698