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

Unified Diff: runtime/lib/string.cc

Issue 11318018: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
Index: runtime/lib/string.cc
===================================================================
--- runtime/lib/string.cc (revision 14314)
+++ runtime/lib/string.cc (working copy)
@@ -15,14 +15,14 @@
GET_NATIVE_ARGUMENT(Array, a, arguments->At(0));
// TODO(srdjan): Check that parameterized type is an int.
Zone* zone = isolate->current_zone();
- intptr_t len = a.Length();
+ intptr_t array_len = a.Length();
// Unbox the array and determine the maximum element width.
bool is_one_byte_string = true;
- bool is_two_byte_string = true;
- uint32_t* temp = zone->Alloc<uint32_t>(len);
+ intptr_t utf16_len = array_len;
+ uint32_t* utf32_array = zone->Alloc<uint32_t>(array_len);
Object& index_object = Object::Handle(isolate);
- for (intptr_t i = 0; i < len; i++) {
+ for (intptr_t i = 0; i < array_len; i++) {
index_object = a.At(i);
if (!index_object.IsSmi()) {
GrowableArray<const Object*> args;
@@ -33,21 +33,20 @@
if (value < 0) {
GrowableArray<const Object*> args;
Exceptions::ThrowByType(Exceptions::kArgument, args);
- } else if (value > 0xFFFF) {
- is_one_byte_string = false;
- is_two_byte_string = false;
- } else if (value > 0xFF) {
- is_one_byte_string = false;
+ } else {
+ if (value > 0x7F) {
+ is_one_byte_string = false;
+ }
+ if (value > 0xFFFF) {
+ utf16_len += 1;
+ }
}
- temp[i] = value;
+ utf32_array[i] = value;
}
if (is_one_byte_string) {
- return OneByteString::New(temp, len, Heap::kNew);
- } else if (is_two_byte_string) {
- return TwoByteString::New(temp, len, Heap::kNew);
- } else {
- return FourByteString::New(temp, len, Heap::kNew);
+ return OneByteString::New(utf32_array, array_len, Heap::kNew);
}
+ return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew);
}
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/benchmark_test.h » ('j') | runtime/vm/dart_api_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698