Chromium Code Reviews| Index: runtime/lib/string.cc |
| diff --git a/runtime/lib/string.cc b/runtime/lib/string.cc |
| index 7707ed63abcb199f12128f13646516d188b0a0dc..f3bb5af9e946f504dec8a6c1dae6c2f44b05d08f 100644 |
| --- a/runtime/lib/string.cc |
| +++ b/runtime/lib/string.cc |
| @@ -11,7 +11,7 @@ |
| namespace dart { |
| -DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
| +DEFINE_NATIVE_ENTRY(StringBase_createFromCodeUnits, 1) { |
|
cshapiro
2012/11/15 20:14:51
I might have missed something, but it seemed clear
erikcorry
2012/11/15 23:47:05
Done.
|
| GET_NATIVE_ARGUMENT(Array, a, arguments->At(0)); |
| // TODO(srdjan): Check that parameterized type is an int. |
| Zone* zone = isolate->current_zone(); |
| @@ -19,7 +19,6 @@ DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
| // Unbox the array and determine the maximum element width. |
| bool is_one_byte_string = true; |
| - 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++) { |
| @@ -29,24 +28,21 @@ DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
| args.Add(&index_object); |
| Exceptions::ThrowByType(Exceptions::kArgument, args); |
| } |
| - intptr_t value = Smi::Cast(index_object).Value(); |
| - if (value < 0) { |
| + uintptr_t value = Smi::Cast(index_object).Value(); |
| + if (value > Utf16::kMaxCodeUnit) { |
| 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(utf16_len, utf32_array, array_len, Heap::kNew); |
| + return TwoByteString::New(array_len, utf32_array, array_len, Heap::kNew); |
| } |
| @@ -76,7 +72,7 @@ DEFINE_NATIVE_ENTRY(String_getLength, 1) { |
| } |
| -static int32_t StringValueAt(const String& str, const Integer& index) { |
| +static int32_t StringCodeUnitAt(const String& str, const Integer& index) { |
| if (index.IsSmi()) { |
| Smi& smi = Smi::Handle(); |
| smi ^= index.raw(); |
| @@ -86,7 +82,7 @@ static int32_t StringValueAt(const String& str, const Integer& index) { |
| arguments.Add(&smi); |
| Exceptions::ThrowByType(Exceptions::kRange, arguments); |
| } |
| - return str.CharAt(index); |
| + return str.CodeUnitAt(index); |
| } else { |
| // An index larger than Smi is always illegal. |
| GrowableArray<const Object*> arguments; |
| @@ -100,17 +96,21 @@ static int32_t StringValueAt(const String& str, const Integer& index) { |
| DEFINE_NATIVE_ENTRY(String_charAt, 2) { |
| const String& receiver = String::CheckedHandle(arguments->At(0)); |
| GET_NATIVE_ARGUMENT(Integer, index, arguments->At(1)); |
| - uint32_t value = StringValueAt(receiver, index); |
| - ASSERT(value <= 0x10FFFF); |
|
cshapiro
2012/11/15 20:14:51
I am not sure why this ASSERT was removed. It is
erikcorry
2012/11/15 23:47:05
In the new version the value is always a UTF-16 co
|
| - return Symbols::New(&value, 1); |
| + uint32_t value = StringCodeUnitAt(receiver, index); |
| + // The VM does not GC interned strings, so we only create max 128 of them. |
| + if (value <= 0x7f) { |
|
cshapiro
2012/11/15 20:14:51
Can we name this constant?
erikcorry
2012/11/15 23:47:05
kFrequentCharacterLimit.
|
| + return Symbols::New(&value, 1); |
| + } else { |
| + return String::New(&value, 1); |
| + } |
| } |
| -DEFINE_NATIVE_ENTRY(String_charCodeAt, 2) { |
| + |
| +DEFINE_NATIVE_ENTRY(String_codeUnitAt, 2) { |
| const String& receiver = String::CheckedHandle(arguments->At(0)); |
| GET_NATIVE_ARGUMENT(Integer, index, arguments->At(1)); |
| - int32_t value = StringValueAt(receiver, index); |
| - ASSERT(value >= 0); |
| - ASSERT(value <= 0x10FFFF); |
| + uint32_t value = StringCodeUnitAt(receiver, index); |
| + ASSERT(value <= Utf16::kMaxCodeUnit); |
| return Smi::New(value); |
| } |