Index: runtime/lib/string.cc |
diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc |
index 75c7ad0854d4b171a4c561ce5f7d865ecf6d4d57..2e1441d1bc8aa49b554ee3e287c8c8e185984554 100644 |
--- a/runtime/lib/string.cc |
+++ b/runtime/lib/string.cc |
@@ -11,7 +11,7 @@ |
namespace dart { |
-DEFINE_NATIVE_ENTRY(StringBase_createFromUtf16, 1) { |
+DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
GET_NATIVE_ARGUMENT(Array, a, arguments->NativeArgAt(0)); |
// TODO(srdjan): Check that parameterized type is an int. |
Zone* zone = isolate->current_zone(); |
@@ -19,7 +19,8 @@ DEFINE_NATIVE_ENTRY(StringBase_createFromUtf16, 1) { |
// Unbox the array and determine the maximum element width. |
bool is_one_byte_string = true; |
- int32_t* utf32_array = zone->Alloc<int32_t>(array_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 < array_len; i++) { |
index_object = a.At(i); |
@@ -29,20 +30,23 @@ DEFINE_NATIVE_ENTRY(StringBase_createFromUtf16, 1) { |
Exceptions::ThrowByType(Exceptions::kArgument, args); |
} |
intptr_t value = Smi::Cast(index_object).Value(); |
- if (value > Utf16::kMaxCodeUnit) { |
+ if (value < 0) { |
GrowableArray<const Object*> args; |
Exceptions::ThrowByType(Exceptions::kArgument, args); |
} else { |
if (value > 0x7F) { |
is_one_byte_string = false; |
} |
+ if (value > 0xFFFF) { |
+ utf16_len += 1; |
+ } |
} |
utf32_array[i] = value; |
} |
if (is_one_byte_string) { |
return OneByteString::New(utf32_array, array_len, Heap::kNew); |
} |
- return TwoByteString::New(array_len, utf32_array, array_len, Heap::kNew); |
+ return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew); |
} |
@@ -72,7 +76,7 @@ DEFINE_NATIVE_ENTRY(String_getLength, 1) { |
} |
-static int32_t StringCodeUnitAt(const String& str, const Integer& index) { |
+static int32_t StringValueAt(const String& str, const Integer& index) { |
if (index.IsSmi()) { |
Smi& smi = Smi::Handle(); |
smi ^= index.raw(); |
@@ -96,23 +100,18 @@ static int32_t StringCodeUnitAt(const String& str, const Integer& index) { |
DEFINE_NATIVE_ENTRY(String_charAt, 2) { |
const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
GET_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1)); |
- uint16_t value = StringCodeUnitAt(receiver, index); |
- // The VM does not GC interned strings, so we only create them for a |
- // restricted range. |
- const int32_t kFrequentCharacterLimit = 0xFF; |
- if (value <= kFrequentCharacterLimit) { |
- return Symbols::FromCharCode(value); |
- } else { |
- return String::New(&value, 1); |
- } |
+ uint32_t value = StringValueAt(receiver, index); |
+ ASSERT(value <= 0x10FFFF); |
+ return Symbols::FromCharCode(value); |
} |
- |
-DEFINE_NATIVE_ENTRY(String_codeUnitAt, 2) { |
+DEFINE_NATIVE_ENTRY(String_charCodeAt, 2) { |
const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
GET_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1)); |
- int32_t value = StringCodeUnitAt(receiver, index); |
- ASSERT(value <= Utf16::kMaxCodeUnit); |
+ |
+ int32_t value = StringValueAt(receiver, index); |
+ ASSERT(value >= 0); |
+ ASSERT(value <= 0x10FFFF); |
return Smi::New(value); |
} |