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

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: Make VM code GC-safer. 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') | runtime/lib/string_buffer_patch.dart » ('J')
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..5221619ec55935b4d69211a4dddba272a917f083 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);
}
-
srdjan 2013/03/05 16:02:21 Why remove the line?
Lasse Reichstein Nielsen 2013/03/05 16:56:56 That was where I originally had the new method. Gu
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,25 @@ DEFINE_NATIVE_ENTRY(Strings_concatAll, 1) {
return String::ConcatAll(strings);
}
+DEFINE_NATIVE_ENTRY(StringBuffer_createStringFromUint16Array, 2) {
srdjan 2013/03/05 16:02:21 Check if you can create OneByteString instead of T
Lasse Reichstein Nielsen 2013/03/05 16:56:56 Will do.
+ 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) {
srdjan 2013/03/05 16:02:21 Add parenthesis (length < 0) || (length > array_le
Lasse Reichstein Nielsen 2013/03/05 16:56:56 Will do.
+ 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 OneByteString::New in that case.
+ const String& result = String::Handle(TwoByteString::New(length, Heap::kNew));
+ NoGCScope no_gc;
+ uint16_t* data_position = reinterpret_cast<uint16_t*>(
+ reinterpret_cast<char*>(a.raw()) +
+ Uint16Array::data_offset() - kHeapObjectTag);
+ String::Copy(result, 0, data_position, length);
+ return result.raw();
+}
+
} // namespace dart
« no previous file with comments | « no previous file | runtime/lib/string_buffer_patch.dart » ('j') | runtime/lib/string_buffer_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698