Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/exceptions.h" | 7 #include "vm/exceptions.h" |
| 8 #include "vm/native_entry.h" | 8 #include "vm/native_entry.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
| 11 #include "vm/unicode.h" | 11 #include "vm/unicode.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { | 15 DEFINE_NATIVE_ENTRY(StringBase_createFromCodePoints, 1) { |
| 16 GET_NON_NULL_NATIVE_ARGUMENT(Array, a, arguments->NativeArgAt(0)); | 16 GET_NON_NULL_NATIVE_ARGUMENT(Instance, list, arguments->NativeArgAt(0)); |
| 17 bool is_growable = list.IsGrowableObjectArray(); | |
| 18 if (!is_growable && !list.IsArray()) { | |
| 19 const Array& args = Array::Handle(Array::New(1)); | |
| 20 args.SetAt(0, list); | |
| 21 Exceptions::ThrowByType(Exceptions::kArgument, args); | |
| 22 } | |
| 17 // TODO(srdjan): Check that parameterized type is an int. | 23 // TODO(srdjan): Check that parameterized type is an int. |
| 24 Array& a = Array::Handle( | |
| 25 is_growable ? GrowableObjectArray::Cast(list).data() | |
| 26 : Array::Cast(list).raw()); | |
| 27 intptr_t array_len = is_growable ? GrowableObjectArray::Cast(list).Length() | |
| 28 : a.Length(); | |
|
siva
2013/03/14 15:56:02
I would structure this code as:
if (!list.IsGrowab
Lasse Reichstein Nielsen
2013/03/15 06:58:40
Much better. Done!
| |
| 29 | |
| 18 Zone* zone = isolate->current_zone(); | 30 Zone* zone = isolate->current_zone(); |
| 19 intptr_t array_len = a.Length(); | |
| 20 | 31 |
| 21 // Unbox the array and determine the maximum element width. | 32 // Unbox the array and determine the maximum element width. |
| 22 bool is_one_byte_string = true; | 33 bool is_one_byte_string = true; |
| 23 intptr_t utf16_len = array_len; | 34 intptr_t utf16_len = array_len; |
| 24 int32_t* utf32_array = zone->Alloc<int32_t>(array_len); | 35 int32_t* utf32_array = zone->Alloc<int32_t>(array_len); |
| 25 Object& index_object = Object::Handle(isolate); | 36 Object& index_object = Object::Handle(isolate); |
| 26 for (intptr_t i = 0; i < array_len; i++) { | 37 for (intptr_t i = 0; i < array_len; i++) { |
| 27 index_object = a.At(i); | 38 index_object = a.At(i); |
| 28 if (!index_object.IsSmi()) { | 39 if (!index_object.IsSmi()) { |
| 29 const Array& args = Array::Handle(Array::New(1)); | 40 const Array& args = Array::Handle(Array::New(1)); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 41 } | 52 } |
| 42 } | 53 } |
| 43 } | 54 } |
| 44 utf32_array[i] = value; | 55 utf32_array[i] = value; |
| 45 } | 56 } |
| 46 if (is_one_byte_string) { | 57 if (is_one_byte_string) { |
| 47 return OneByteString::New(utf32_array, array_len, Heap::kNew); | 58 return OneByteString::New(utf32_array, array_len, Heap::kNew); |
| 48 } | 59 } |
| 49 return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew); | 60 return TwoByteString::New(utf16_len, utf32_array, array_len, Heap::kNew); |
| 50 } | 61 } |
| 51 | 62 |
|
siva
2013/03/14 15:56:02
Why remove the blank line here, we normally have 2
Lasse Reichstein Nielsen
2013/03/15 06:58:40
No reason. I moved the body of the method into a h
| |
| 52 | |
| 53 DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) { | 63 DEFINE_NATIVE_ENTRY(StringBase_substringUnchecked, 3) { |
| 54 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); | 64 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
| 55 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); | 65 GET_NON_NULL_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); |
| 56 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); | 66 GET_NON_NULL_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); |
| 57 | 67 |
| 58 intptr_t start = start_obj.Value(); | 68 intptr_t start = start_obj.Value(); |
| 59 intptr_t end = end_obj.Value(); | 69 intptr_t end = end_obj.Value(); |
| 60 return String::SubString(receiver, start, (end - start)); | 70 return String::SubString(receiver, start, (end - start)); |
| 61 } | 71 } |
| 62 | 72 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) | 224 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) |
| 215 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); | 225 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); |
| 216 NoGCScope no_gc; | 226 NoGCScope no_gc; |
| 217 | 227 |
| 218 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.ByteAddr(0)); | 228 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.ByteAddr(0)); |
| 219 String::Copy(result, 0, data_position, length_value); | 229 String::Copy(result, 0, data_position, length_value); |
| 220 return result.raw(); | 230 return result.raw(); |
| 221 } | 231 } |
| 222 | 232 |
| 223 } // namespace dart | 233 } // namespace dart |
| OLD | NEW |