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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 ASSERT(receiver.IsOneByteString()); | 67 ASSERT(receiver.IsOneByteString()); |
| 68 GET_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); | 68 GET_NATIVE_ARGUMENT(Smi, start_obj, arguments->NativeArgAt(1)); |
| 69 GET_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); | 69 GET_NATIVE_ARGUMENT(Smi, end_obj, arguments->NativeArgAt(2)); |
| 70 | 70 |
| 71 const intptr_t start = start_obj.Value(); | 71 const intptr_t start = start_obj.Value(); |
| 72 const intptr_t end = end_obj.Value(); | 72 const intptr_t end = end_obj.Value(); |
| 73 return OneByteString::New(receiver, start, end - start, Heap::kNew); | 73 return OneByteString::New(receiver, start, end - start, Heap::kNew); |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 // This is high-performance code. | |
| 77 DEFINE_NATIVE_ENTRY(OneByteString_splitWithCharCode, 2) { | 78 DEFINE_NATIVE_ENTRY(OneByteString_splitWithCharCode, 2) { |
| 78 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); | 79 // 'isolate' is defined. |
|
siva
2012/12/04 03:04:50
we have used isolate in the rest of the file with
srdjan
2012/12/04 21:41:30
Removed comment. I think it would be better if 'is
| |
| 80 const String& receiver = String::CheckedHandle(isolate, | |
| 81 arguments->NativeArgAt(0)); | |
| 79 ASSERT(receiver.IsOneByteString()); | 82 ASSERT(receiver.IsOneByteString()); |
| 80 GET_NATIVE_ARGUMENT(Smi, smi_split_code, arguments->NativeArgAt(1)); | 83 GET_NATIVE_ARGUMENT(Smi, smi_split_code, arguments->NativeArgAt(1)); |
| 81 const intptr_t len = receiver.Length(); | 84 const intptr_t len = receiver.Length(); |
| 82 const intptr_t split_code = smi_split_code.Value(); | 85 const intptr_t split_code = smi_split_code.Value(); |
| 83 const GrowableObjectArray& result = GrowableObjectArray::Handle( | 86 const GrowableObjectArray& result = GrowableObjectArray::Handle( |
| 84 GrowableObjectArray::New(4, Heap::kNew)); | 87 isolate, |
| 85 String& str = String::Handle(); | 88 GrowableObjectArray::New(16, Heap::kNew)); |
| 89 String& str = String::Handle(isolate); | |
| 86 intptr_t start = 0; | 90 intptr_t start = 0; |
| 87 intptr_t i = 0; | 91 intptr_t i = 0; |
| 88 for (; i < len; i++) { | 92 for (; i < len; i++) { |
| 89 if (split_code == receiver.CharAt(i)) { | 93 if (split_code == OneByteString::CharAt(receiver, i)) { |
| 90 str = String::SubString(receiver, start, (i - start)); | 94 str = OneByteString::SubStringUnchecked(receiver, |
| 91 result.Add(str); | 95 start, |
| 96 (i - start), | |
| 97 isolate, | |
|
siva
2012/12/04 03:04:50
If we have to pass isolate as a parameter I would
srdjan
2012/12/04 21:41:30
Done.
| |
| 98 Heap::kNew); | |
| 99 result.Add(str, isolate); | |
|
siva
2012/12/04 03:04:50
Ditto comment.
srdjan
2012/12/04 21:41:30
Done.
| |
| 92 start = i + 1; | 100 start = i + 1; |
| 93 } | 101 } |
| 94 } | 102 } |
| 95 str = String::SubString(receiver, start, (i - start)); | 103 str = OneByteString::SubStringUnchecked(receiver, |
| 96 result.Add(str); | 104 start, |
| 105 (i - start), | |
| 106 isolate, | |
| 107 Heap::kNew); | |
| 108 result.Add(str, isolate); | |
| 97 return result.raw(); | 109 return result.raw(); |
| 98 } | 110 } |
| 99 | 111 |
| 100 | 112 |
| 101 DEFINE_NATIVE_ENTRY(String_getHashCode, 1) { | 113 DEFINE_NATIVE_ENTRY(String_getHashCode, 1) { |
| 102 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); | 114 const String& receiver = String::CheckedHandle(arguments->NativeArgAt(0)); |
| 103 intptr_t hash_val = receiver.Hash(); | 115 intptr_t hash_val = receiver.Hash(); |
| 104 ASSERT(hash_val > 0); | 116 ASSERT(hash_val > 0); |
| 105 ASSERT(Smi::IsValid(hash_val)); | 117 ASSERT(Smi::IsValid(hash_val)); |
| 106 return Smi::New(hash_val); | 118 return Smi::New(hash_val); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 if (!elem.IsString()) { | 196 if (!elem.IsString()) { |
| 185 GrowableArray<const Object*> args; | 197 GrowableArray<const Object*> args; |
| 186 args.Add(&elem); | 198 args.Add(&elem); |
| 187 Exceptions::ThrowByType(Exceptions::kArgument, args); | 199 Exceptions::ThrowByType(Exceptions::kArgument, args); |
| 188 } | 200 } |
| 189 } | 201 } |
| 190 return String::ConcatAll(strings); | 202 return String::ConcatAll(strings); |
| 191 } | 203 } |
| 192 | 204 |
| 193 } // namespace dart | 205 } // namespace dart |
| OLD | NEW |