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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 560113002: Narrow String::CharAt from int32_t to uint16_t. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months 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 | « runtime/lib/string.cc ('k') | runtime/vm/flow_graph_optimizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 intptr_t* length) { 2299 intptr_t* length) {
2300 Isolate* isolate = Isolate::Current(); 2300 Isolate* isolate = Isolate::Current();
2301 DARTSCOPE(isolate); 2301 DARTSCOPE(isolate);
2302 const String& str_obj = Api::UnwrapStringHandle(isolate, str); 2302 const String& str_obj = Api::UnwrapStringHandle(isolate, str);
2303 if (str_obj.IsNull()) { 2303 if (str_obj.IsNull()) {
2304 RETURN_TYPE_ERROR(isolate, str, String); 2304 RETURN_TYPE_ERROR(isolate, str, String);
2305 } 2305 }
2306 intptr_t str_len = str_obj.Length(); 2306 intptr_t str_len = str_obj.Length();
2307 intptr_t copy_len = (str_len > *length) ? *length : str_len; 2307 intptr_t copy_len = (str_len > *length) ? *length : str_len;
2308 for (intptr_t i = 0; i < copy_len; i++) { 2308 for (intptr_t i = 0; i < copy_len; i++) {
2309 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); 2309 utf16_array[i] = str_obj.CharAt(i);
2310 } 2310 }
2311 *length = copy_len; 2311 *length = copy_len;
2312 return Api::Success(); 2312 return Api::Success();
2313 } 2313 }
2314 2314
2315 2315
2316 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, 2316 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str,
2317 intptr_t* size) { 2317 intptr_t* size) {
2318 Isolate* isolate = Isolate::Current(); 2318 Isolate* isolate = Isolate::Current();
2319 CHECK_ISOLATE(isolate); 2319 CHECK_ISOLATE(isolate);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2366 uint8_t* latin1_array = reinterpret_cast<uint8_t*>(array); 2366 uint8_t* latin1_array = reinterpret_cast<uint8_t*>(array);
2367 for (intptr_t i = 0; i < copy_len; i++) { 2367 for (intptr_t i = 0; i < copy_len; i++) {
2368 latin1_array[i] = static_cast<uint8_t>(str_obj.CharAt(i)); 2368 latin1_array[i] = static_cast<uint8_t>(str_obj.CharAt(i));
2369 } 2369 }
2370 OneByteString::SetPeer(str_obj, peer, cback); 2370 OneByteString::SetPeer(str_obj, peer, cback);
2371 } else { 2371 } else {
2372 ASSERT(str_obj.IsTwoByteString()); 2372 ASSERT(str_obj.IsTwoByteString());
2373 ASSERT(length >= (copy_len * str_obj.CharSize())); 2373 ASSERT(length >= (copy_len * str_obj.CharSize()));
2374 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array); 2374 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array);
2375 for (intptr_t i = 0; i < copy_len; i++) { 2375 for (intptr_t i = 0; i < copy_len; i++) {
2376 utf16_array[i] = static_cast<uint16_t>(str_obj.CharAt(i)); 2376 utf16_array[i] = str_obj.CharAt(i);
2377 } 2377 }
2378 TwoByteString::SetPeer(str_obj, peer, cback); 2378 TwoByteString::SetPeer(str_obj, peer, cback);
2379 } 2379 }
2380 return str; 2380 return str;
2381 } 2381 }
2382 return Api::NewHandle(isolate, 2382 return Api::NewHandle(isolate,
2383 str_obj.MakeExternal(array, length, peer, cback)); 2383 str_obj.MakeExternal(array, length, peer, cback));
2384 } 2384 }
2385 2385
2386 2386
(...skipping 2997 matching lines...) Expand 10 before | Expand all | Expand 10 after
5384 5384
5385 5385
5386 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5386 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5387 const char* name, 5387 const char* name,
5388 Dart_ServiceRequestCallback callback, 5388 Dart_ServiceRequestCallback callback,
5389 void* user_data) { 5389 void* user_data) {
5390 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5390 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5391 } 5391 }
5392 5392
5393 } // namespace dart 5393 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/string.cc ('k') | runtime/vm/flow_graph_optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698