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

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

Issue 2275803002: Assign external sizes to external strings and to external typed data created by the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync Created 4 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
« no previous file with comments | « runtime/vm/clustered_snapshot.cc ('k') | runtime/vm/object.h » ('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 "lib/stacktrace.h" 10 #include "lib/stacktrace.h"
(...skipping 2539 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 if (size == NULL) { 2550 if (size == NULL) {
2551 RETURN_NULL_ERROR(size); 2551 RETURN_NULL_ERROR(size);
2552 } 2552 }
2553 *size = (str_obj.Length() * str_obj.CharSize()); 2553 *size = (str_obj.Length() * str_obj.CharSize());
2554 return Api::Success(); 2554 return Api::Success();
2555 } 2555 }
2556 2556
2557 2557
2558 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, 2558 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str,
2559 void* array, 2559 void* array,
2560 intptr_t length, 2560 intptr_t external_size,
2561 void* peer, 2561 void* peer,
2562 Dart_PeerFinalizer cback) { 2562 Dart_PeerFinalizer cback) {
2563 DARTSCOPE(Thread::Current()); 2563 DARTSCOPE(Thread::Current());
2564 if (!FLAG_support_externalizable_strings) { 2564 if (!FLAG_support_externalizable_strings) {
2565 return Api::NewError("Dart_MakeExternalString with " 2565 return Api::NewError("Dart_MakeExternalString with "
2566 "--support_externalizable_strings=false"); 2566 "--support_externalizable_strings=false");
2567 } 2567 }
2568 const String& str_obj = Api::UnwrapStringHandle(Z, str); 2568 const String& str_obj = Api::UnwrapStringHandle(Z, str);
2569 if (str_obj.IsExternal()) { 2569 if (str_obj.IsExternal()) {
2570 return str; // String is already an external string. 2570 return str; // String is already an external string.
2571 } 2571 }
2572 if (str_obj.IsNull()) { 2572 if (str_obj.IsNull()) {
2573 RETURN_TYPE_ERROR(Z, str, String); 2573 RETURN_TYPE_ERROR(Z, str, String);
2574 } 2574 }
2575 if (array == NULL) { 2575 if (array == NULL) {
2576 RETURN_NULL_ERROR(array); 2576 RETURN_NULL_ERROR(array);
2577 } 2577 }
2578 intptr_t str_size = (str_obj.Length() * str_obj.CharSize()); 2578 intptr_t str_size = (str_obj.Length() * str_obj.CharSize());
2579 if ((length < str_size) || (length > String::kMaxElements)) { 2579 if ((external_size < str_size) || (external_size > String::kMaxElements)) {
2580 return Api::NewError("Dart_MakeExternalString " 2580 return Api::NewError("Dart_MakeExternalString "
2581 "expects argument length to be in the range" 2581 "expects argument external_size to be in the range"
2582 "[%" Pd "..%" Pd "].", 2582 "[%" Pd "..%" Pd "].",
2583 str_size, String::kMaxElements); 2583 str_size, String::kMaxElements);
2584 } 2584 }
2585 if (str_obj.InVMHeap()) { 2585 if (str_obj.InVMHeap()) {
2586 // Since the string object is read only we do not externalize 2586 // Since the string object is read only we do not externalize
2587 // the string but instead copy the contents of the string into the 2587 // the string but instead copy the contents of the string into the
2588 // specified buffer add the specified peer/cback as a Peer object 2588 // specified buffer add the specified peer/cback as a Peer object
2589 // to this string. The Api::StringGetPeerHelper function picks up 2589 // to this string. The Api::StringGetPeerHelper function picks up
2590 // the peer from the Peer table. 2590 // the peer from the Peer table.
2591 intptr_t copy_len = str_obj.Length(); 2591 intptr_t copy_len = str_obj.Length();
2592 if (str_obj.IsOneByteString()) { 2592 if (str_obj.IsOneByteString()) {
2593 ASSERT(length >= copy_len); 2593 ASSERT(external_size >= copy_len);
2594 uint8_t* latin1_array = reinterpret_cast<uint8_t*>(array); 2594 uint8_t* latin1_array = reinterpret_cast<uint8_t*>(array);
2595 for (intptr_t i = 0; i < copy_len; i++) { 2595 for (intptr_t i = 0; i < copy_len; i++) {
2596 latin1_array[i] = static_cast<uint8_t>(str_obj.CharAt(i)); 2596 latin1_array[i] = static_cast<uint8_t>(str_obj.CharAt(i));
2597 } 2597 }
2598 OneByteString::SetPeer(str_obj, peer, cback); 2598 OneByteString::SetPeer(str_obj, external_size, peer, cback);
2599 } else { 2599 } else {
2600 ASSERT(str_obj.IsTwoByteString()); 2600 ASSERT(str_obj.IsTwoByteString());
2601 ASSERT(length >= (copy_len * str_obj.CharSize())); 2601 ASSERT(external_size >= (copy_len * str_obj.CharSize()));
2602 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array); 2602 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array);
2603 for (intptr_t i = 0; i < copy_len; i++) { 2603 for (intptr_t i = 0; i < copy_len; i++) {
2604 utf16_array[i] = str_obj.CharAt(i); 2604 utf16_array[i] = str_obj.CharAt(i);
2605 } 2605 }
2606 TwoByteString::SetPeer(str_obj, peer, cback); 2606 TwoByteString::SetPeer(str_obj, external_size, peer, cback);
2607 } 2607 }
2608 return str; 2608 return str;
2609 } 2609 }
2610 return Api::NewHandle(T, str_obj.MakeExternal(array, length, peer, cback)); 2610 return Api::NewHandle(T, str_obj.MakeExternal(array, external_size,
2611 peer, cback));
2611 } 2612 }
2612 2613
2613 2614
2614 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, 2615 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object,
2615 intptr_t* char_size, 2616 intptr_t* char_size,
2616 intptr_t* str_len, 2617 intptr_t* str_len,
2617 void** peer) { 2618 void** peer) {
2618 Thread* thread = Thread::Current(); 2619 Thread* thread = Thread::Current();
2619 CHECK_ISOLATE(thread->isolate()); 2620 CHECK_ISOLATE(thread->isolate());
2620 ReusableObjectHandleScope reused_obj_handle(thread); 2621 ReusableObjectHandleScope reused_obj_handle(thread);
(...skipping 3962 matching lines...) Expand 10 before | Expand all | Expand 10 after
6583 6584
6584 DART_EXPORT bool Dart_IsPrecompiledRuntime() { 6585 DART_EXPORT bool Dart_IsPrecompiledRuntime() {
6585 #if defined(DART_PRECOMPILED_RUNTIME) 6586 #if defined(DART_PRECOMPILED_RUNTIME)
6586 return true; 6587 return true;
6587 #else 6588 #else
6588 return false; 6589 return false;
6589 #endif 6590 #endif
6590 } 6591 }
6591 6592
6592 } // namespace dart 6593 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/clustered_snapshot.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698