Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: runtime/lib/string.cc

Issue 74423005: Add optimized String.fromCharCodes path for Uint8List and Int8List. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/string_patch.dart » ('j') | runtime/lib/string_patch.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return result.raw(); 145 return result.raw();
146 } 146 }
147 147
148 148
149 DEFINE_NATIVE_ENTRY(OneByteString_allocate, 1) { 149 DEFINE_NATIVE_ENTRY(OneByteString_allocate, 1) {
150 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length_obj, arguments->NativeArgAt(0)); 150 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length_obj, arguments->NativeArgAt(0));
151 return OneByteString::New(length_obj.Value(), Heap::kNew); 151 return OneByteString::New(length_obj.Value(), Heap::kNew);
152 } 152 }
153 153
154 154
155 DEFINE_NATIVE_ENTRY(OneByteString_allocateFromOneByteList, 1) {
156 const Object& list = Object::Handle(arguments->NativeArgAt(0));
srdjan 2013/11/18 20:45:15 Instance::CheckedHandle(arguments->NativeArgAt(0))
Anders Johnsen 2013/11/19 07:38:43 Done.
157 uint8_t* data = NULL;
158 intptr_t length = 0;
159 if (list.IsTypedData()) {
160 const TypedData& array = TypedData::Cast(list);
161 length = array.LengthInBytes();
162 data = reinterpret_cast<uint8_t*>(array.DataAddr(0));
163 } else if (list.IsExternalTypedData()) {
164 const ExternalTypedData& array = ExternalTypedData::Cast(list);
165 length = array.LengthInBytes();
166 data = reinterpret_cast<uint8_t*>(array.DataAddr(0));
167 } else if (RawObject::IsTypedDataViewClassId(list.GetClassId())) {
168 const Instance& view = Instance::Cast(list);
169 length = Smi::Value(TypedDataView::Length(view));
170 const Instance& data_obj = Instance::Handle(TypedDataView::Data(view));
171 intptr_t data_offset = Smi::Value(TypedDataView::OffsetInBytes(view));
172 if (data_obj.IsTypedData()) {
173 const TypedData& array = TypedData::Cast(data_obj);
174 data = reinterpret_cast<uint8_t*>(array.DataAddr(data_offset));
175 } else if (data_obj.IsExternalTypedData()) {
176 const ExternalTypedData& array = ExternalTypedData::Cast(data_obj);
177 data = reinterpret_cast<uint8_t*>(array.DataAddr(data_offset));
178 } else {
179 UNREACHABLE();
180 }
181 } else if (list.IsArray()) {
182 const Array& array = Array::Cast(list);
183 intptr_t length = array.Length();
184 String& string = String::Handle(OneByteString::New(length, Heap::kNew));
185 for (int i = 0; i < length; i++) {
186 intptr_t value = Smi::Value(reinterpret_cast<RawSmi*>(array.At(i)));
187 OneByteString::SetCharAt(string, i, value);
188 }
189 return string.raw();
190 } else if (list.IsGrowableObjectArray()) {
191 const GrowableObjectArray& array = GrowableObjectArray::Cast(list);
192 intptr_t length = array.Length();
193 String& string = String::Handle(OneByteString::New(length, Heap::kNew));
194 for (int i = 0; i < length; i++) {
195 intptr_t value = Smi::Value(reinterpret_cast<RawSmi*>(array.At(i)));
196 OneByteString::SetCharAt(string, i, value);
197 }
198 return string.raw();
199 } else {
200 UNREACHABLE();
201 }
202 return OneByteString::New(data, length, Heap::kNew);
203 }
204
205
155 DEFINE_NATIVE_ENTRY(OneByteString_setAt, 3) { 206 DEFINE_NATIVE_ENTRY(OneByteString_setAt, 3) {
156 GET_NON_NULL_NATIVE_ARGUMENT(String, receiver, arguments->NativeArgAt(0)); 207 GET_NON_NULL_NATIVE_ARGUMENT(String, receiver, arguments->NativeArgAt(0));
157 ASSERT(receiver.IsOneByteString()); 208 ASSERT(receiver.IsOneByteString());
158 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index_obj, arguments->NativeArgAt(1)); 209 GET_NON_NULL_NATIVE_ARGUMENT(Smi, index_obj, arguments->NativeArgAt(1));
159 GET_NON_NULL_NATIVE_ARGUMENT(Smi, code_point_obj, arguments->NativeArgAt(2)); 210 GET_NON_NULL_NATIVE_ARGUMENT(Smi, code_point_obj, arguments->NativeArgAt(2));
160 ASSERT((0 <= code_point_obj.Value()) && (code_point_obj.Value() <= 0xFF)); 211 ASSERT((0 <= code_point_obj.Value()) && (code_point_obj.Value() <= 0xFF));
161 OneByteString::SetCharAt(receiver, index_obj.Value(), code_point_obj.Value()); 212 OneByteString::SetCharAt(receiver, index_obj.Value(), code_point_obj.Value());
162 return Object::null(); 213 return Object::null();
163 } 214 }
164 215
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 ? String::Handle(OneByteString::New(length_value, Heap::kNew)) 346 ? String::Handle(OneByteString::New(length_value, Heap::kNew))
296 : String::Handle(TwoByteString::New(length_value, Heap::kNew)); 347 : String::Handle(TwoByteString::New(length_value, Heap::kNew));
297 NoGCScope no_gc; 348 NoGCScope no_gc;
298 349
299 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0)); 350 uint16_t* data_position = reinterpret_cast<uint16_t*>(codeUnits.DataAddr(0));
300 String::Copy(result, 0, data_position, length_value); 351 String::Copy(result, 0, data_position, length_value);
301 return result.raw(); 352 return result.raw();
302 } 353 }
303 354
304 } // namespace dart 355 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/string_patch.dart » ('j') | runtime/lib/string_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698