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

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

Issue 8383029: Implement external strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: pre-review clean-up Created 9 years, 2 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
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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 HandleScope scope; // Setup a VM handle scope. 716 HandleScope scope; // Setup a VM handle scope.
717 const String& obj = String::Handle(String::New(codepoints, length)); 717 const String& obj = String::Handle(String::New(codepoints, length));
718 return Api::NewLocalHandle(obj); 718 return Api::NewLocalHandle(obj);
719 } 719 }
720 720
721 721
722 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, 722 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
723 intptr_t length) { 723 intptr_t length) {
724 Zone zone; // Setup a VM zone as we are creating some handles. 724 Zone zone; // Setup a VM zone as we are creating some handles.
725 HandleScope scope; // Setup a VM handle scope. 725 HandleScope scope; // Setup a VM handle scope.
726 UNIMPLEMENTED();
727 const String& obj = String::Handle(String::New(codepoints, length)); 726 const String& obj = String::Handle(String::New(codepoints, length));
728 return Api::NewLocalHandle(obj); 727 return Api::NewLocalHandle(obj);
729 } 728 }
730 729
731 730
731 DART_EXPORT Dart_Handle Dart_NewExternalString8(
732 uint8_t* codepoints,
733 intptr_t length,
734 Dart_ExternalString8Finalizer finalizer) {
735 Zone zone; // Setup a VM zone as we are creating some handles.
736 HandleScope scope; // Setup a VM handle scope.
737 const String& obj =
738 String::Handle(
739 ExternalOneByteString::New(codepoints, length, finalizer));
740 return Api::NewLocalHandle(obj);
741 }
742
743
744 DART_EXPORT Dart_Handle Dart_NewExternalString16(
745 uint16_t* codepoints,
746 intptr_t length,
747 Dart_ExternalString16Finalizer finalizer) {
748 Zone zone; // Setup a VM zone as we are creating some handles.
749 HandleScope scope; // Setup a VM handle scope.
750 const String& obj =
751 String::Handle(
752 ExternalTwoByteString::New(codepoints, length, finalizer));
753 return Api::NewLocalHandle(obj);
754 }
755
756
757 DART_EXPORT Dart_Handle Dart_NewExternalString32(
758 uint32_t* codepoints,
759 intptr_t length,
760 Dart_ExternalString32Finalizer finalizer) {
761 Zone zone; // Setup a VM zone as we are creating some handles.
762 HandleScope scope; // Setup a VM handle scope.
763 const String& obj =
764 String::Handle(
765 ExternalFourByteString::New(codepoints, length, finalizer));
766 return Api::NewLocalHandle(obj);
767 }
768
769
732 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { 770 DART_EXPORT bool Dart_IsString8(Dart_Handle object) {
733 Zone zone; // Setup a VM zone as we are creating some handles. 771 Zone zone; // Setup a VM zone as we are creating some handles.
734 HandleScope scope; // Setup a VM handle scope. 772 HandleScope scope; // Setup a VM handle scope.
735 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 773 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
736 return obj.IsOneByteString(); 774 return obj.IsOneByteString() || obj.IsExternalOneByteString();
737 } 775 }
738 776
739 777
740 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { 778 DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
741 Zone zone; // Setup a VM zone as we are creating some handles. 779 Zone zone; // Setup a VM zone as we are creating some handles.
742 HandleScope scope; // Setup a VM handle scope. 780 HandleScope scope; // Setup a VM handle scope.
743 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 781 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
744 return obj.IsOneByteString() || obj.IsTwoByteString(); 782 return (obj.IsOneByteString() || obj.IsExternalOneByteString() ||
783 obj.IsTwoByteString() || obj.IsExternalOneByteString());
745 } 784 }
746 785
747 786
748 DART_EXPORT Dart_Result Dart_StringGet8(Dart_Handle str, 787 DART_EXPORT Dart_Result Dart_StringGet8(Dart_Handle str,
749 uint8_t* codepoints, 788 uint8_t* codepoints,
750 intptr_t length) { 789 intptr_t length) {
turnidge 2011/10/25 18:07:20 You have updated the Dart_isString* functions but
cshapiro 2011/10/25 20:42:47 Nope, that was an oversight..
751 Zone zone; // Setup a VM zone as we are creating some handles. 790 Zone zone; // Setup a VM zone as we are creating some handles.
752 HandleScope scope; // Setup a VM handle scope. 791 HandleScope scope; // Setup a VM handle scope.
753 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 792 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
754 if (obj.IsOneByteString()) { 793 if (obj.IsOneByteString()) {
755 OneByteString& string_obj = OneByteString::Handle(); 794 OneByteString& string_obj = OneByteString::Handle();
756 string_obj ^= obj.raw(); 795 string_obj ^= obj.raw();
757 intptr_t str_len = string_obj.Length(); 796 intptr_t str_len = string_obj.Length();
758 intptr_t copy_len = (str_len > length) ? length : str_len; 797 intptr_t copy_len = (str_len > length) ? length : str_len;
759 for (intptr_t i = 0; i < copy_len; i++) { 798 for (intptr_t i = 0; i < copy_len; i++) {
760 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); 799 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 ASSERT(isolate != NULL); 1760 ASSERT(isolate != NULL);
1722 ApiState* state = isolate->api_state(); 1761 ApiState* state = isolate->api_state();
1723 ASSERT(state != NULL); 1762 ASSERT(state != NULL);
1724 ApiLocalScope* scope = state->top_scope(); 1763 ApiLocalScope* scope = state->top_scope();
1725 ASSERT(scope != NULL); 1764 ASSERT(scope != NULL);
1726 return scope->zone().Reallocate(ptr, old_size, new_size); 1765 return scope->zone().Reallocate(ptr, old_size, new_size);
1727 } 1766 }
1728 1767
1729 1768
1730 } // namespace dart 1769 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698