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

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: Fully displace external string metadata Created 9 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
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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 784
785 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, 785 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
786 intptr_t length) { 786 intptr_t length) {
787 Zone zone; // Setup a VM zone as we are creating some handles. 787 Zone zone; // Setup a VM zone as we are creating some handles.
788 HandleScope scope; // Setup a VM handle scope. 788 HandleScope scope; // Setup a VM handle scope.
789 const String& obj = String::Handle(String::New(codepoints, length)); 789 const String& obj = String::Handle(String::New(codepoints, length));
790 return Api::NewLocalHandle(obj); 790 return Api::NewLocalHandle(obj);
791 } 791 }
792 792
793 793
794 DART_EXPORT Dart_Handle Dart_NewExternalString8(uint8_t* codepoints,
795 intptr_t length,
796 void* peer,
797 Dart_PeerFinalizer callback) {
798 Zone zone; // Setup a VM zone as we are creating some handles.
799 HandleScope scope; // Setup a VM handle scope.
siva 2011/11/18 23:26:09 When you sync up these two lines will be replaced
cshapiro 2011/11/19 01:08:29 Thanks for pointing this out. I discovered the ch
800 const String& obj =
801 String::Handle(String::NewExternal(codepoints, length, peer, callback));
802 return Api::NewLocalHandle(obj);
803 }
804
805
806 DART_EXPORT Dart_Handle Dart_NewExternalString16(uint16_t* codepoints,
807 intptr_t length,
808 void* peer,
809 Dart_PeerFinalizer callback) {
810 Zone zone; // Setup a VM zone as we are creating some handles.
811 HandleScope scope; // Setup a VM handle scope.
812 const String& obj =
813 String::Handle(String::NewExternal(codepoints, length, peer, callback));
814 return Api::NewLocalHandle(obj);
815 }
816
817
818 DART_EXPORT Dart_Handle Dart_NewExternalString32(uint32_t* codepoints,
819 intptr_t length,
820 void* peer,
821 Dart_PeerFinalizer callback) {
822 Zone zone; // Setup a VM zone as we are creating some handles.
823 HandleScope scope; // Setup a VM handle scope.
824 const String& obj =
825 String::Handle(String::NewExternal(codepoints, length, peer, callback));
826 return Api::NewLocalHandle(obj);
827 }
828
829
794 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { 830 DART_EXPORT bool Dart_IsString8(Dart_Handle object) {
795 Zone zone; // Setup a VM zone as we are creating some handles. 831 Zone zone; // Setup a VM zone as we are creating some handles.
796 HandleScope scope; // Setup a VM handle scope. 832 HandleScope scope; // Setup a VM handle scope.
797 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 833 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
798 return obj.IsOneByteString(); 834 return obj.IsOneByteString() || obj.IsExternalOneByteString();
799 } 835 }
800 836
801 837
802 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { 838 DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
803 Zone zone; // Setup a VM zone as we are creating some handles. 839 Zone zone; // Setup a VM zone as we are creating some handles.
804 HandleScope scope; // Setup a VM handle scope. 840 HandleScope scope; // Setup a VM handle scope.
805 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 841 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
806 return obj.IsOneByteString() || obj.IsTwoByteString(); 842 return (obj.IsOneByteString() || obj.IsExternalOneByteString() ||
843 obj.IsTwoByteString() || obj.IsExternalOneByteString());
Ivan Posva 2011/11/18 19:36:44 obj.IsExternalOneByteString() -> obj.IsExternalTwo
cshapiro 2011/11/19 01:08:29 Fixed. I could not find any tests for this functi
807 } 844 }
808 845
809 846
810 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, 847 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
811 uint8_t* codepoints, 848 uint8_t* codepoints,
812 intptr_t* length) { 849 intptr_t* length) {
813 Zone zone; // Setup a VM zone as we are creating some handles. 850 Zone zone; // Setup a VM zone as we are creating some handles.
814 HandleScope scope; // Setup a VM handle scope. 851 HandleScope scope; // Setup a VM handle scope.
815 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 852 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
816 if (obj.IsOneByteString()) { 853 if (obj.IsString()) {
817 OneByteString& string_obj = OneByteString::Handle(); 854 String& string_obj = String::Handle();
siva 2011/11/18 23:26:09 If you manage to get your change in before Todd th
818 string_obj ^= obj.raw(); 855 string_obj ^= obj.raw();
819 intptr_t str_len = string_obj.Length(); 856 if (string_obj.CharSize() == String::kOneByteChar) {
820 intptr_t copy_len = (str_len > *length) ? *length : str_len; 857 intptr_t str_len = string_obj.Length();
821 for (intptr_t i = 0; i < copy_len; i++) { 858 intptr_t copy_len = (str_len > *length) ? *length : str_len;
822 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i)); 859 for (intptr_t i = 0; i < copy_len; i++) {
860 codepoints[i] = static_cast<uint8_t>(string_obj.CharAt(i));
861 }
862 *length= copy_len;
863 return Api::Success();
823 } 864 }
824 *length= copy_len;
825 return Api::Success();
826 } 865 }
827 return Api::Error(obj.IsString() 866 return Api::Error(obj.IsString()
828 ? "Object is not a String8" 867 ? "Object is not a String8"
829 : "Object is not a String"); 868 : "Object is not a String");
830 } 869 }
831 870
832 871
833 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, 872 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str,
834 uint16_t* codepoints, 873 uint16_t* codepoints,
835 intptr_t* length) { 874 intptr_t* length) {
836 Zone zone; // Setup a VM zone as we are creating some handles. 875 Zone zone; // Setup a VM zone as we are creating some handles.
837 HandleScope scope; // Setup a VM handle scope. 876 HandleScope scope; // Setup a VM handle scope.
838 const Object& obj = Object::Handle(Api::UnwrapHandle(str)); 877 const Object& obj = Object::Handle(Api::UnwrapHandle(str));
839 if (obj.IsOneByteString() || obj.IsTwoByteString()) { 878 if (obj.IsString()) {
840 String& string_obj = String::Handle(); 879 String& string_obj = String::Handle();
841 string_obj ^= obj.raw(); 880 string_obj ^= obj.raw();
842 intptr_t str_len = string_obj.Length(); 881 if (string_obj.CharSize() <= String::kTwoByteChar) {
843 intptr_t copy_len = (str_len > *length) ? *length : str_len; 882 intptr_t str_len = string_obj.Length();
844 for (intptr_t i = 0; i < copy_len; i++) { 883 intptr_t copy_len = (str_len > *length) ? *length : str_len;
845 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i)); 884 for (intptr_t i = 0; i < copy_len; i++) {
885 codepoints[i] = static_cast<uint16_t>(string_obj.CharAt(i));
886 }
887 *length = copy_len;
888 return Api::Success();
846 } 889 }
847 *length = copy_len;
848 return Api::Success();
849 } 890 }
850 return Api::Error(obj.IsString() 891 return Api::Error(obj.IsString()
851 ? "Object is not a String16" 892 ? "Object is not a String16"
852 : "Object is not a String"); 893 : "Object is not a String");
853 } 894 }
854 895
855 896
856 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, 897 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str,
857 uint32_t* codepoints, 898 uint32_t* codepoints,
858 intptr_t* length) { 899 intptr_t* length) {
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 ASSERT(isolate != NULL); 2124 ASSERT(isolate != NULL);
2084 ApiState* state = isolate->api_state(); 2125 ApiState* state = isolate->api_state();
2085 ASSERT(state != NULL); 2126 ASSERT(state != NULL);
2086 ApiLocalScope* scope = state->top_scope(); 2127 ApiLocalScope* scope = state->top_scope();
2087 ASSERT(scope != NULL); 2128 ASSERT(scope != NULL);
2088 return scope->zone().Reallocate(ptr, old_size, new_size); 2129 return scope->zone().Reallocate(ptr, old_size, new_size);
2089 } 2130 }
2090 2131
2091 2132
2092 } // namespace dart 2133 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698