Chromium Code Reviews| 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 |