| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ASSERT(!IsNull()); | 171 ASSERT(!IsNull()); |
| 172 raw()->SetCanonical(); | 172 raw()->SetCanonical(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 inline RawClass* clazz() const; | 175 inline RawClass* clazz() const; |
| 176 static intptr_t tags_offset() { return OFFSET_OF(RawObject, tags_); } | 176 static intptr_t tags_offset() { return OFFSET_OF(RawObject, tags_); } |
| 177 | 177 |
| 178 // Class testers. | 178 // Class testers. |
| 179 #define DEFINE_CLASS_TESTER(clazz) \ | 179 #define DEFINE_CLASS_TESTER(clazz) \ |
| 180 virtual bool Is##clazz() const { return false; } | 180 virtual bool Is##clazz() const { return false; } |
| 181 CLASS_LIST_NO_OBJECT(DEFINE_CLASS_TESTER); | 181 CLASS_LIST_FOR_HANDLES(DEFINE_CLASS_TESTER); |
| 182 #undef DEFINE_CLASS_TESTER | 182 #undef DEFINE_CLASS_TESTER |
| 183 | 183 |
| 184 bool IsNull() const { return raw_ == null_; } | 184 bool IsNull() const { return raw_ == null_; } |
| 185 | 185 |
| 186 virtual const char* ToCString() const { | 186 virtual const char* ToCString() const { |
| 187 if (IsNull()) { | 187 if (IsNull()) { |
| 188 return "null"; | 188 return "null"; |
| 189 } else { | 189 } else { |
| 190 return "Object"; | 190 return "Object"; |
| 191 } | 191 } |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 static RawClass* New(const String& name, | 708 static RawClass* New(const String& name, |
| 709 const Script& script, | 709 const Script& script, |
| 710 intptr_t token_pos); | 710 intptr_t token_pos); |
| 711 static RawClass* NewInterface(const String& name, | 711 static RawClass* NewInterface(const String& name, |
| 712 const Script& script, | 712 const Script& script, |
| 713 intptr_t token_pos); | 713 intptr_t token_pos); |
| 714 static RawClass* NewNativeWrapper(const Library& library, | 714 static RawClass* NewNativeWrapper(const Library& library, |
| 715 const String& name, | 715 const String& name, |
| 716 int num_fields); | 716 int num_fields); |
| 717 | 717 |
| 718 // Allocate the raw string classes. |
| 719 static RawClass* NewStringClass(intptr_t class_id); |
| 720 |
| 718 // Allocate a class representing a function signature described by | 721 // Allocate a class representing a function signature described by |
| 719 // signature_function, which must be a closure function or a signature | 722 // signature_function, which must be a closure function or a signature |
| 720 // function. | 723 // function. |
| 721 // The class may be type parameterized unless the signature_function is in a | 724 // The class may be type parameterized unless the signature_function is in a |
| 722 // static scope. In that case, the type parameters are copied from the owner | 725 // static scope. In that case, the type parameters are copied from the owner |
| 723 // class of signature_function. | 726 // class of signature_function. |
| 724 static RawClass* NewSignatureClass(const String& name, | 727 static RawClass* NewSignatureClass(const String& name, |
| 725 const Function& signature_function, | 728 const Function& signature_function, |
| 726 const Script& script); | 729 const Script& script); |
| 727 | 730 |
| (...skipping 2924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3652 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } | 3655 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } |
| 3653 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } | 3656 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } |
| 3654 | 3657 |
| 3655 virtual intptr_t Hash() const; | 3658 virtual intptr_t Hash() const; |
| 3656 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } | 3659 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
| 3657 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); | 3660 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
| 3658 static intptr_t Hash(const uint8_t* characters, intptr_t len); | 3661 static intptr_t Hash(const uint8_t* characters, intptr_t len); |
| 3659 static intptr_t Hash(const uint16_t* characters, intptr_t len); | 3662 static intptr_t Hash(const uint16_t* characters, intptr_t len); |
| 3660 static intptr_t Hash(const uint32_t* characters, intptr_t len); | 3663 static intptr_t Hash(const uint32_t* characters, intptr_t len); |
| 3661 | 3664 |
| 3662 virtual int32_t CharAt(intptr_t index) const; | 3665 int32_t CharAt(intptr_t index) const; |
| 3663 | 3666 |
| 3664 virtual intptr_t CharSize() const; | 3667 intptr_t CharSize() const; |
| 3665 | 3668 |
| 3666 inline bool Equals(const String& str) const; | 3669 inline bool Equals(const String& str) const; |
| 3667 inline bool Equals(const String& str, | 3670 inline bool Equals(const String& str, |
| 3668 intptr_t begin_index, // begin index on 'str'. | 3671 intptr_t begin_index, // begin index on 'str'. |
| 3669 intptr_t len) const; // len on 'str'. | 3672 intptr_t len) const; // len on 'str'. |
| 3670 bool Equals(const char* str) const; | 3673 bool Equals(const char* str) const; |
| 3671 bool Equals(const uint8_t* characters, intptr_t len) const; | 3674 bool Equals(const uint8_t* characters, intptr_t len) const; |
| 3672 bool Equals(const uint16_t* characters, intptr_t len) const; | 3675 bool Equals(const uint16_t* characters, intptr_t len) const; |
| 3673 bool Equals(const uint32_t* characters, intptr_t len) const; | 3676 bool Equals(const uint32_t* characters, intptr_t len) const; |
| 3674 | 3677 |
| 3675 virtual bool Equals(const Instance& other) const; | 3678 virtual bool Equals(const Instance& other) const; |
| 3676 | 3679 |
| 3677 intptr_t CompareTo(const String& other) const; | 3680 intptr_t CompareTo(const String& other) const; |
| 3678 | 3681 |
| 3679 bool StartsWith(const String& other) const; | 3682 bool StartsWith(const String& other) const; |
| 3680 | 3683 |
| 3681 virtual RawInstance* Canonicalize() const; | 3684 virtual RawInstance* Canonicalize() const; |
| 3682 | 3685 |
| 3683 bool IsSymbol() const { return raw()->IsCanonical(); } | 3686 bool IsSymbol() const { return raw()->IsCanonical(); } |
| 3684 | 3687 |
| 3685 virtual bool IsExternal() const { return false; } | 3688 bool IsOneByteString() const { |
| 3686 virtual void* GetPeer() const { | 3689 return raw()->GetClassId() == kOneByteStringCid; |
| 3687 UNREACHABLE(); | |
| 3688 return NULL; | |
| 3689 } | 3690 } |
| 3690 | 3691 |
| 3692 bool IsTwoByteString() const { |
| 3693 return raw()->GetClassId() == kTwoByteStringCid; |
| 3694 } |
| 3695 |
| 3696 bool IsExternalOneByteString() const { |
| 3697 return raw()->GetClassId() == kExternalOneByteStringCid; |
| 3698 } |
| 3699 |
| 3700 bool IsExternalTwoByteString() const { |
| 3701 return raw()->GetClassId() == kExternalTwoByteStringCid; |
| 3702 } |
| 3703 |
| 3704 bool IsExternal() const { |
| 3705 return RawObject::IsExternalStringClassId(raw()->GetClassId()); |
| 3706 } |
| 3707 |
| 3708 void* GetPeer() const; |
| 3709 |
| 3691 void ToUTF8(uint8_t* utf8_array, intptr_t array_len) const; | 3710 void ToUTF8(uint8_t* utf8_array, intptr_t array_len) const; |
| 3692 | 3711 |
| 3693 // Creates a new String object from a C string that is assumed to contain | 3712 // Creates a new String object from a C string that is assumed to contain |
| 3694 // UTF-8 encoded characters and '\0' is considered a termination character. | 3713 // UTF-8 encoded characters and '\0' is considered a termination character. |
| 3695 static RawString* New(const char* cstr, Heap::Space space = Heap::kNew); | 3714 static RawString* New(const char* cstr, Heap::Space space = Heap::kNew); |
| 3696 | 3715 |
| 3697 // Creates a new String object from an array of UTF-8 encoded characters. | 3716 // Creates a new String object from an array of UTF-8 encoded characters. |
| 3698 static RawString* New(const uint8_t* utf8_array, | 3717 static RawString* New(const uint8_t* utf8_array, |
| 3699 intptr_t array_len, | 3718 intptr_t array_len, |
| 3700 Heap::Space space = Heap::kNew); | 3719 Heap::Space space = Heap::kNew); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3784 } | 3803 } |
| 3785 | 3804 |
| 3786 void SetHash(intptr_t value) const { | 3805 void SetHash(intptr_t value) const { |
| 3787 // This is only safe because we create a new Smi, which does not cause | 3806 // This is only safe because we create a new Smi, which does not cause |
| 3788 // heap allocation. | 3807 // heap allocation. |
| 3789 raw_ptr()->hash_ = Smi::New(value); | 3808 raw_ptr()->hash_ = Smi::New(value); |
| 3790 } | 3809 } |
| 3791 | 3810 |
| 3792 template<typename HandleType, typename ElementType> | 3811 template<typename HandleType, typename ElementType> |
| 3793 static void ReadFromImpl(SnapshotReader* reader, | 3812 static void ReadFromImpl(SnapshotReader* reader, |
| 3794 HandleType* str_obj, | 3813 String* str_obj, |
| 3795 intptr_t len, | 3814 intptr_t len, |
| 3796 intptr_t tags, | 3815 intptr_t tags, |
| 3797 Snapshot::Kind kind); | 3816 Snapshot::Kind kind); |
| 3798 | 3817 |
| 3799 HEAP_OBJECT_IMPLEMENTATION(String, Instance); | 3818 HEAP_OBJECT_IMPLEMENTATION(String, Instance); |
| 3800 | 3819 |
| 3820 friend class Class; |
| 3801 friend class Symbols; | 3821 friend class Symbols; |
| 3822 friend class OneByteString; |
| 3823 friend class TwoByteString; |
| 3824 friend class ExternalOneByteString; |
| 3825 friend class ExternalTwoByteString; |
| 3802 }; | 3826 }; |
| 3803 | 3827 |
| 3804 | 3828 |
| 3805 class OneByteString : public String { | 3829 class OneByteString : public AllStatic { |
| 3806 public: | 3830 public: |
| 3807 virtual int32_t CharAt(intptr_t index) const { | 3831 static int32_t CharAt(const String& str, intptr_t index) { |
| 3808 return *CharAddr(index); | 3832 return *CharAddr(str, index); |
| 3809 } | 3833 } |
| 3810 | 3834 |
| 3811 virtual intptr_t CharSize() const { | 3835 static RawOneByteString* EscapeSpecialCharacters(const String& str, |
| 3812 return kOneByteChar; | 3836 bool raw_str); |
| 3813 } | |
| 3814 | 3837 |
| 3815 RawOneByteString* EscapeSpecialCharacters(bool raw_str) const; | 3838 static bool EqualsIgnoringPrivateKey(const String& str1, |
| 3816 | 3839 const String& str2); |
| 3817 bool EqualsIgnoringPrivateKey(const OneByteString& str) const; | |
| 3818 | 3840 |
| 3819 // We use the same maximum elements for all strings. | 3841 // We use the same maximum elements for all strings. |
| 3820 static const intptr_t kBytesPerElement = 1; | 3842 static const intptr_t kBytesPerElement = 1; |
| 3821 static const intptr_t kMaxElements = String::kMaxElements; | 3843 static const intptr_t kMaxElements = String::kMaxElements; |
| 3822 | 3844 |
| 3823 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); } | 3845 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); } |
| 3824 | 3846 |
| 3825 static intptr_t InstanceSize() { | 3847 static intptr_t InstanceSize() { |
| 3826 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); | 3848 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); |
| 3827 return 0; | 3849 return 0; |
| 3828 } | 3850 } |
| 3829 | 3851 |
| 3830 static intptr_t InstanceSize(intptr_t len) { | 3852 static intptr_t InstanceSize(intptr_t len) { |
| 3831 ASSERT(sizeof(RawOneByteString) == kSizeofRawString); | 3853 ASSERT(sizeof(RawOneByteString) == String::kSizeofRawString); |
| 3832 ASSERT(0 <= len && len <= kMaxElements); | 3854 ASSERT(0 <= len && len <= kMaxElements); |
| 3833 return RoundedAllocationSize( | 3855 return String::RoundedAllocationSize( |
| 3834 sizeof(RawOneByteString) + (len * kBytesPerElement)); | 3856 sizeof(RawOneByteString) + (len * kBytesPerElement)); |
| 3835 } | 3857 } |
| 3836 | 3858 |
| 3837 static RawOneByteString* New(intptr_t len, | 3859 static RawOneByteString* New(intptr_t len, |
| 3838 Heap::Space space); | 3860 Heap::Space space); |
| 3839 static RawOneByteString* New(const char* c_string, | 3861 static RawOneByteString* New(const char* c_string, |
| 3840 Heap::Space space = Heap::kNew) { | 3862 Heap::Space space = Heap::kNew) { |
| 3841 return New(reinterpret_cast<const uint8_t*>(c_string), | 3863 return New(reinterpret_cast<const uint8_t*>(c_string), |
| 3842 strlen(c_string), | 3864 strlen(c_string), |
| 3843 space); | 3865 space); |
| 3844 } | 3866 } |
| 3845 static RawOneByteString* New(const uint8_t* characters, | 3867 static RawOneByteString* New(const uint8_t* characters, |
| 3846 intptr_t len, | 3868 intptr_t len, |
| 3847 Heap::Space space); | 3869 Heap::Space space); |
| 3848 static RawOneByteString* New(const uint16_t* characters, | 3870 static RawOneByteString* New(const uint16_t* characters, |
| 3849 intptr_t len, | 3871 intptr_t len, |
| 3850 Heap::Space space); | 3872 Heap::Space space); |
| 3851 static RawOneByteString* New(const uint32_t* characters, | 3873 static RawOneByteString* New(const uint32_t* characters, |
| 3852 intptr_t len, | 3874 intptr_t len, |
| 3853 Heap::Space space); | 3875 Heap::Space space); |
| 3854 static RawOneByteString* New(const OneByteString& str, | 3876 static RawOneByteString* New(const String& str, |
| 3855 Heap::Space space); | 3877 Heap::Space space); |
| 3856 | 3878 |
| 3857 static RawOneByteString* Concat(const String& str1, | 3879 static RawOneByteString* Concat(const String& str1, |
| 3858 const String& str2, | 3880 const String& str2, |
| 3859 Heap::Space space); | 3881 Heap::Space space); |
| 3860 static RawOneByteString* ConcatAll(const Array& strings, | 3882 static RawOneByteString* ConcatAll(const Array& strings, |
| 3861 intptr_t len, | 3883 intptr_t len, |
| 3862 Heap::Space space); | 3884 Heap::Space space); |
| 3863 | 3885 |
| 3864 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), | 3886 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), |
| 3865 const String& str, | 3887 const String& str, |
| 3866 Heap::Space space); | 3888 Heap::Space space); |
| 3867 | 3889 |
| 3868 private: | 3890 static const ClassId kClassId = kOneByteStringCid; |
| 3869 uint8_t* CharAddr(intptr_t index) const { | 3891 |
| 3870 // TODO(iposva): Determine if we should throw an exception here. | 3892 static RawOneByteString* null() { |
| 3871 ASSERT((index >= 0) && (index < Length())); | 3893 return reinterpret_cast<RawOneByteString*>(Object::null()); |
| 3872 return &raw_ptr()->data_[index]; | |
| 3873 } | 3894 } |
| 3874 | 3895 |
| 3875 HEAP_OBJECT_IMPLEMENTATION(OneByteString, String); | 3896 private: |
| 3897 static RawOneByteString* raw(const String& str) { |
| 3898 return reinterpret_cast<RawOneByteString*>(str.raw()); |
| 3899 } |
| 3900 |
| 3901 static RawOneByteString* raw_ptr(const String& str) { |
| 3902 return reinterpret_cast<RawOneByteString*>(str.raw_ptr()); |
| 3903 } |
| 3904 |
| 3905 static uint8_t* CharAddr(const String& str, intptr_t index) { |
| 3906 ASSERT((index >= 0) && (index < str.Length())); |
| 3907 ASSERT(str.IsOneByteString()); |
| 3908 NoGCScope no_gc; |
| 3909 return &raw_ptr(str)->data_[index]; |
| 3910 } |
| 3911 |
| 3912 static RawOneByteString* ReadFrom(SnapshotReader* reader, |
| 3913 intptr_t object_id, |
| 3914 intptr_t tags, |
| 3915 Snapshot::Kind kind); |
| 3916 |
| 3876 friend class Class; | 3917 friend class Class; |
| 3877 friend class String; | 3918 friend class String; |
| 3919 friend class SnapshotReader; |
| 3878 }; | 3920 }; |
| 3879 | 3921 |
| 3880 | 3922 |
| 3881 class TwoByteString : public String { | 3923 class TwoByteString : public AllStatic { |
| 3882 public: | 3924 public: |
| 3883 virtual int32_t CharAt(intptr_t index) const { | 3925 static int32_t CharAt(const String& str, intptr_t index) { |
| 3884 return *CharAddr(index); | 3926 return *CharAddr(str, index); |
| 3885 } | 3927 } |
| 3886 | 3928 |
| 3887 virtual intptr_t CharSize() const { | 3929 static RawTwoByteString* EscapeSpecialCharacters(const String& str, |
| 3888 return kTwoByteChar; | 3930 bool raw_str); |
| 3889 } | |
| 3890 | |
| 3891 RawTwoByteString* EscapeSpecialCharacters(bool raw_str) const; | |
| 3892 | 3931 |
| 3893 // We use the same maximum elements for all strings. | 3932 // We use the same maximum elements for all strings. |
| 3894 static const intptr_t kBytesPerElement = 2; | 3933 static const intptr_t kBytesPerElement = 2; |
| 3895 static const intptr_t kMaxElements = String::kMaxElements; | 3934 static const intptr_t kMaxElements = String::kMaxElements; |
| 3896 | 3935 |
| 3897 static intptr_t data_offset() { return OFFSET_OF(RawTwoByteString, data_); } | 3936 static intptr_t data_offset() { return OFFSET_OF(RawTwoByteString, data_); } |
| 3898 | 3937 |
| 3899 static intptr_t InstanceSize() { | 3938 static intptr_t InstanceSize() { |
| 3900 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_)); | 3939 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_)); |
| 3901 return 0; | 3940 return 0; |
| 3902 } | 3941 } |
| 3903 | 3942 |
| 3904 static intptr_t InstanceSize(intptr_t len) { | 3943 static intptr_t InstanceSize(intptr_t len) { |
| 3905 ASSERT(sizeof(RawTwoByteString) == kSizeofRawString); | 3944 ASSERT(sizeof(RawTwoByteString) == String::kSizeofRawString); |
| 3906 ASSERT(0 <= len && len <= kMaxElements); | 3945 ASSERT(0 <= len && len <= kMaxElements); |
| 3907 return RoundedAllocationSize( | 3946 return String::RoundedAllocationSize( |
| 3908 sizeof(RawTwoByteString) + (len * kBytesPerElement)); | 3947 sizeof(RawTwoByteString) + (len * kBytesPerElement)); |
| 3909 } | 3948 } |
| 3910 | 3949 |
| 3911 static RawTwoByteString* New(intptr_t len, | 3950 static RawTwoByteString* New(intptr_t len, |
| 3912 Heap::Space space); | 3951 Heap::Space space); |
| 3913 static RawTwoByteString* New(const uint16_t* characters, | 3952 static RawTwoByteString* New(const uint16_t* characters, |
| 3914 intptr_t len, | 3953 intptr_t len, |
| 3915 Heap::Space space); | 3954 Heap::Space space); |
| 3916 static RawTwoByteString* New(intptr_t utf16_len, | 3955 static RawTwoByteString* New(intptr_t utf16_len, |
| 3917 const uint32_t* characters, | 3956 const uint32_t* characters, |
| 3918 intptr_t len, | 3957 intptr_t len, |
| 3919 Heap::Space space); | 3958 Heap::Space space); |
| 3920 static RawTwoByteString* New(const TwoByteString& str, | 3959 static RawTwoByteString* New(const String& str, |
| 3921 Heap::Space space); | 3960 Heap::Space space); |
| 3922 | 3961 |
| 3923 static RawTwoByteString* Concat(const String& str1, | 3962 static RawTwoByteString* Concat(const String& str1, |
| 3924 const String& str2, | 3963 const String& str2, |
| 3925 Heap::Space space); | 3964 Heap::Space space); |
| 3926 static RawTwoByteString* ConcatAll(const Array& strings, | 3965 static RawTwoByteString* ConcatAll(const Array& strings, |
| 3927 intptr_t len, | 3966 intptr_t len, |
| 3928 Heap::Space space); | 3967 Heap::Space space); |
| 3929 | 3968 |
| 3930 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), | 3969 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), |
| 3931 const String& str, | 3970 const String& str, |
| 3932 Heap::Space space); | 3971 Heap::Space space); |
| 3933 | 3972 |
| 3934 private: | 3973 static RawTwoByteString* null() { |
| 3935 uint16_t* CharAddr(intptr_t index) const { | 3974 return reinterpret_cast<RawTwoByteString*>(Object::null()); |
| 3936 ASSERT((index >= 0) && (index < Length())); | |
| 3937 return &raw_ptr()->data_[index]; | |
| 3938 } | 3975 } |
| 3939 | 3976 |
| 3940 HEAP_OBJECT_IMPLEMENTATION(TwoByteString, String); | 3977 |
| 3978 static const ClassId kClassId = kTwoByteStringCid; |
| 3979 |
| 3980 private: |
| 3981 static RawTwoByteString* raw(const String& str) { |
| 3982 return reinterpret_cast<RawTwoByteString*>(str.raw()); |
| 3983 } |
| 3984 |
| 3985 static RawTwoByteString* raw_ptr(const String& str) { |
| 3986 return reinterpret_cast<RawTwoByteString*>(str.raw_ptr()); |
| 3987 } |
| 3988 |
| 3989 static uint16_t* CharAddr(const String& str, intptr_t index) { |
| 3990 ASSERT((index >= 0) && (index < str.Length())); |
| 3991 ASSERT(str.IsTwoByteString()); |
| 3992 NoGCScope no_gc; |
| 3993 return &raw_ptr(str)->data_[index]; |
| 3994 } |
| 3995 |
| 3996 static RawTwoByteString* ReadFrom(SnapshotReader* reader, |
| 3997 intptr_t object_id, |
| 3998 intptr_t tags, |
| 3999 Snapshot::Kind kind); |
| 4000 |
| 3941 friend class Class; | 4001 friend class Class; |
| 3942 friend class String; | 4002 friend class String; |
| 4003 friend class SnapshotReader; |
| 3943 }; | 4004 }; |
| 3944 | 4005 |
| 3945 | 4006 |
| 3946 class ExternalOneByteString : public String { | 4007 class ExternalOneByteString : public AllStatic { |
| 3947 public: | 4008 public: |
| 3948 virtual int32_t CharAt(intptr_t index) const { | 4009 static int32_t CharAt(const String& str, intptr_t index) { |
| 3949 return *CharAddr(index); | 4010 return *CharAddr(str, index); |
| 3950 } | 4011 } |
| 3951 | 4012 |
| 3952 virtual intptr_t CharSize() const { | 4013 static void* GetPeer(const String& str) { |
| 3953 return kOneByteChar; | 4014 return raw_ptr(str)->external_data_->peer(); |
| 3954 } | |
| 3955 | |
| 3956 virtual bool IsExternal() const { return true; } | |
| 3957 virtual void* GetPeer() const { | |
| 3958 return raw_ptr()->external_data_->peer(); | |
| 3959 } | 4015 } |
| 3960 | 4016 |
| 3961 // We use the same maximum elements for all strings. | 4017 // We use the same maximum elements for all strings. |
| 3962 static const intptr_t kBytesPerElement = 1; | 4018 static const intptr_t kBytesPerElement = 1; |
| 3963 static const intptr_t kMaxElements = String::kMaxElements; | 4019 static const intptr_t kMaxElements = String::kMaxElements; |
| 3964 | 4020 |
| 3965 static intptr_t InstanceSize() { | 4021 static intptr_t InstanceSize() { |
| 3966 return RoundedAllocationSize(sizeof(RawExternalOneByteString)); | 4022 return String::RoundedAllocationSize(sizeof(RawExternalOneByteString)); |
| 3967 } | 4023 } |
| 3968 | 4024 |
| 3969 static RawExternalOneByteString* New(const uint8_t* characters, | 4025 static RawExternalOneByteString* New(const uint8_t* characters, |
| 3970 intptr_t len, | 4026 intptr_t len, |
| 3971 void* peer, | 4027 void* peer, |
| 3972 Dart_PeerFinalizer callback, | 4028 Dart_PeerFinalizer callback, |
| 3973 Heap::Space space); | 4029 Heap::Space space); |
| 3974 | 4030 |
| 3975 private: | 4031 static RawExternalOneByteString* null() { |
| 3976 const uint8_t* CharAddr(intptr_t index) const { | 4032 return reinterpret_cast<RawExternalOneByteString*>(Object::null()); |
| 3977 // TODO(iposva): Determine if we should throw an exception here. | |
| 3978 ASSERT((index >= 0) && (index < Length())); | |
| 3979 return &(raw_ptr()->external_data_->data()[index]); | |
| 3980 } | 4033 } |
| 3981 | 4034 |
| 3982 void SetExternalData(ExternalStringData<uint8_t>* data) { | 4035 static const ClassId kClassId = kExternalOneByteStringCid; |
| 3983 raw_ptr()->external_data_ = data; | 4036 |
| 4037 private: |
| 4038 static RawExternalOneByteString* raw(const String& str) { |
| 4039 return reinterpret_cast<RawExternalOneByteString*>(str.raw()); |
| 4040 } |
| 4041 |
| 4042 static RawExternalOneByteString* raw_ptr(const String& str) { |
| 4043 return reinterpret_cast<RawExternalOneByteString*>(str.raw_ptr()); |
| 4044 } |
| 4045 |
| 4046 static const uint8_t* CharAddr(const String& str, intptr_t index) { |
| 4047 ASSERT((index >= 0) && (index < str.Length())); |
| 4048 ASSERT(str.IsExternalOneByteString()); |
| 4049 NoGCScope no_gc; |
| 4050 return &(raw_ptr(str)->external_data_->data()[index]); |
| 4051 } |
| 4052 |
| 4053 static void SetExternalData(const String& str, |
| 4054 ExternalStringData<uint8_t>* data) { |
| 4055 ASSERT(str.IsExternalOneByteString()); |
| 4056 NoGCScope no_gc; |
| 4057 raw_ptr(str)->external_data_ = data; |
| 3984 } | 4058 } |
| 3985 | 4059 |
| 3986 static void Finalize(Dart_Handle handle, void* peer); | 4060 static void Finalize(Dart_Handle handle, void* peer); |
| 3987 | 4061 |
| 3988 HEAP_OBJECT_IMPLEMENTATION(ExternalOneByteString, String); | 4062 static RawExternalOneByteString* ReadFrom(SnapshotReader* reader, |
| 4063 intptr_t object_id, |
| 4064 intptr_t tags, |
| 4065 Snapshot::Kind kind); |
| 4066 |
| 3989 friend class Class; | 4067 friend class Class; |
| 3990 friend class String; | 4068 friend class String; |
| 4069 friend class SnapshotReader; |
| 3991 }; | 4070 }; |
| 3992 | 4071 |
| 3993 | 4072 |
| 3994 class ExternalTwoByteString : public String { | 4073 class ExternalTwoByteString : public AllStatic { |
| 3995 public: | 4074 public: |
| 3996 virtual int32_t CharAt(intptr_t index) const { | 4075 static int32_t CharAt(const String& str, intptr_t index) { |
| 3997 return *CharAddr(index); | 4076 return *CharAddr(str, index); |
| 3998 } | 4077 } |
| 3999 | 4078 |
| 4000 virtual intptr_t CharSize() const { | 4079 static void* GetPeer(const String& str) { |
| 4001 return kTwoByteChar; | 4080 return raw_ptr(str)->external_data_->peer(); |
| 4002 } | |
| 4003 | |
| 4004 virtual bool IsExternal() const { return true; } | |
| 4005 virtual void* GetPeer() const { | |
| 4006 return raw_ptr()->external_data_->peer(); | |
| 4007 } | 4081 } |
| 4008 | 4082 |
| 4009 // We use the same maximum elements for all strings. | 4083 // We use the same maximum elements for all strings. |
| 4010 static const intptr_t kBytesPerElement = 2; | 4084 static const intptr_t kBytesPerElement = 2; |
| 4011 static const intptr_t kMaxElements = String::kMaxElements; | 4085 static const intptr_t kMaxElements = String::kMaxElements; |
| 4012 | 4086 |
| 4013 static intptr_t InstanceSize() { | 4087 static intptr_t InstanceSize() { |
| 4014 return RoundedAllocationSize(sizeof(RawExternalTwoByteString)); | 4088 return String::RoundedAllocationSize(sizeof(RawExternalTwoByteString)); |
| 4015 } | 4089 } |
| 4016 | 4090 |
| 4017 static RawExternalTwoByteString* New(const uint16_t* characters, | 4091 static RawExternalTwoByteString* New(const uint16_t* characters, |
| 4018 intptr_t len, | 4092 intptr_t len, |
| 4019 void* peer, | 4093 void* peer, |
| 4020 Dart_PeerFinalizer callback, | 4094 Dart_PeerFinalizer callback, |
| 4021 Heap::Space space = Heap::kNew); | 4095 Heap::Space space = Heap::kNew); |
| 4022 | 4096 |
| 4023 private: | 4097 static RawExternalTwoByteString* null() { |
| 4024 const uint16_t* CharAddr(intptr_t index) const { | 4098 return reinterpret_cast<RawExternalTwoByteString*>(Object::null()); |
| 4025 // TODO(iposva): Determine if we should throw an exception here. | |
| 4026 ASSERT((index >= 0) && (index < Length())); | |
| 4027 return &(raw_ptr()->external_data_->data()[index]); | |
| 4028 } | 4099 } |
| 4029 | 4100 |
| 4030 void SetExternalData(ExternalStringData<uint16_t>* data) { | 4101 static const ClassId kClassId = kExternalTwoByteStringCid; |
| 4031 raw_ptr()->external_data_ = data; | 4102 |
| 4103 private: |
| 4104 static RawExternalTwoByteString* raw(const String& str) { |
| 4105 return reinterpret_cast<RawExternalTwoByteString*>(str.raw()); |
| 4106 } |
| 4107 |
| 4108 static RawExternalTwoByteString* raw_ptr(const String& str) { |
| 4109 return reinterpret_cast<RawExternalTwoByteString*>(str.raw_ptr()); |
| 4110 } |
| 4111 |
| 4112 static const uint16_t* CharAddr(const String& str, intptr_t index) { |
| 4113 ASSERT((index >= 0) && (index < str.Length())); |
| 4114 ASSERT(str.IsExternalTwoByteString()); |
| 4115 NoGCScope no_gc; |
| 4116 return &(raw_ptr(str)->external_data_->data()[index]); |
| 4117 } |
| 4118 |
| 4119 static void SetExternalData(const String& str, |
| 4120 ExternalStringData<uint16_t>* data) { |
| 4121 ASSERT(str.IsExternalTwoByteString()); |
| 4122 NoGCScope no_gc; |
| 4123 raw_ptr(str)->external_data_ = data; |
| 4032 } | 4124 } |
| 4033 | 4125 |
| 4034 static void Finalize(Dart_Handle handle, void* peer); | 4126 static void Finalize(Dart_Handle handle, void* peer); |
| 4035 | 4127 |
| 4036 HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString, String); | 4128 static RawExternalTwoByteString* ReadFrom(SnapshotReader* reader, |
| 4129 intptr_t object_id, |
| 4130 intptr_t tags, |
| 4131 Snapshot::Kind kind); |
| 4132 |
| 4037 friend class Class; | 4133 friend class Class; |
| 4038 friend class String; | 4134 friend class String; |
| 4135 friend class SnapshotReader; |
| 4039 }; | 4136 }; |
| 4040 | 4137 |
| 4041 | 4138 |
| 4042 // Class Bool implements Dart core class bool. | 4139 // Class Bool implements Dart core class bool. |
| 4043 class Bool : public Instance { | 4140 class Bool : public Instance { |
| 4044 public: | 4141 public: |
| 4045 bool value() const { | 4142 bool value() const { |
| 4046 return raw_ptr()->value_; | 4143 return raw_ptr()->value_; |
| 4047 } | 4144 } |
| 4048 | 4145 |
| (...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5749 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5846 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5750 return false; | 5847 return false; |
| 5751 } | 5848 } |
| 5752 } | 5849 } |
| 5753 return true; | 5850 return true; |
| 5754 } | 5851 } |
| 5755 | 5852 |
| 5756 } // namespace dart | 5853 } // namespace dart |
| 5757 | 5854 |
| 5758 #endif // VM_OBJECT_H_ | 5855 #endif // VM_OBJECT_H_ |
| OLD | NEW |