Chromium Code Reviews| 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_NO_OBJECT_WITH_STRING(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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3782 // heap allocation. | 3801 // heap allocation. |
| 3783 raw_ptr()->length_ = Smi::New(value); | 3802 raw_ptr()->length_ = Smi::New(value); |
| 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> |
|
siva
2012/11/05 19:23:38
HandleType should probably be called StringType as
| |
| 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 private: |
| 3948 virtual int32_t CharAt(intptr_t index) const { | 4009 static RawExternalOneByteString* raw_str(const String& str) { |
| 3949 return *CharAddr(index); | 4010 return reinterpret_cast<RawExternalOneByteString*>(str.raw_ptr()); |
| 3950 } | 4011 } |
|
siva
2012/11/05 19:23:38
Normally we put private methods after all the publ
Tom Ball
2012/11/05 21:22:41
This method was added before the other methods wer
| |
| 3951 | 4012 |
| 3952 virtual intptr_t CharSize() const { | 4013 public: |
| 3953 return kOneByteChar; | 4014 static int32_t CharAt(const String& str, intptr_t index) { |
| 4015 return *CharAddr(str, index); | |
| 3954 } | 4016 } |
| 3955 | 4017 |
| 3956 virtual bool IsExternal() const { return true; } | 4018 static void* GetPeer(const String& str) { |
| 3957 virtual void* GetPeer() const { | 4019 return raw_str(str)->external_data_->peer(); |
| 3958 return raw_ptr()->external_data_->peer(); | |
| 3959 } | 4020 } |
| 3960 | 4021 |
| 3961 // We use the same maximum elements for all strings. | 4022 // We use the same maximum elements for all strings. |
| 3962 static const intptr_t kBytesPerElement = 1; | 4023 static const intptr_t kBytesPerElement = 1; |
| 3963 static const intptr_t kMaxElements = String::kMaxElements; | 4024 static const intptr_t kMaxElements = String::kMaxElements; |
| 3964 | 4025 |
| 3965 static intptr_t InstanceSize() { | 4026 static intptr_t InstanceSize() { |
| 3966 return RoundedAllocationSize(sizeof(RawExternalOneByteString)); | 4027 return String::RoundedAllocationSize(sizeof(RawExternalOneByteString)); |
| 3967 } | 4028 } |
| 3968 | 4029 |
| 3969 static RawExternalOneByteString* New(const uint8_t* characters, | 4030 static RawExternalOneByteString* New(const uint8_t* characters, |
| 3970 intptr_t len, | 4031 intptr_t len, |
| 3971 void* peer, | 4032 void* peer, |
| 3972 Dart_PeerFinalizer callback, | 4033 Dart_PeerFinalizer callback, |
| 3973 Heap::Space space); | 4034 Heap::Space space); |
| 3974 | 4035 |
| 3975 private: | 4036 static RawExternalOneByteString* null() { |
| 3976 const uint8_t* CharAddr(intptr_t index) const { | 4037 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 } | 4038 } |
| 3981 | 4039 |
| 3982 void SetExternalData(ExternalStringData<uint8_t>* data) { | 4040 static const ClassId kClassId = kExternalOneByteStringCid; |
| 3983 raw_ptr()->external_data_ = data; | 4041 |
| 4042 private: | |
| 4043 static RawExternalOneByteString* raw(const String& str) { | |
| 4044 return reinterpret_cast<RawExternalOneByteString*>(str.raw()); | |
| 4045 } | |
| 4046 | |
| 4047 static const uint8_t* CharAddr(const String& str, intptr_t index) { | |
| 4048 ASSERT((index >= 0) && (index < str.Length())); | |
| 4049 ASSERT(str.IsExternalOneByteString()); | |
| 4050 NoGCScope no_gc; | |
| 4051 return &(raw_str(str)->external_data_->data()[index]); | |
| 4052 } | |
| 4053 | |
| 4054 static void SetExternalData(const String& str, | |
| 4055 ExternalStringData<uint8_t>* data) { | |
| 4056 ASSERT(str.IsExternalOneByteString()); | |
| 4057 NoGCScope no_gc; | |
| 4058 raw_str(str)->external_data_ = data; | |
| 3984 } | 4059 } |
| 3985 | 4060 |
| 3986 static void Finalize(Dart_Handle handle, void* peer); | 4061 static void Finalize(Dart_Handle handle, void* peer); |
| 3987 | 4062 |
| 3988 HEAP_OBJECT_IMPLEMENTATION(ExternalOneByteString, String); | 4063 static RawExternalOneByteString* ReadFrom(SnapshotReader* reader, |
| 4064 intptr_t object_id, | |
| 4065 intptr_t tags, | |
| 4066 Snapshot::Kind kind); | |
| 4067 | |
| 3989 friend class Class; | 4068 friend class Class; |
| 3990 friend class String; | 4069 friend class String; |
| 4070 friend class SnapshotReader; | |
| 3991 }; | 4071 }; |
| 3992 | 4072 |
| 3993 | 4073 |
| 3994 class ExternalTwoByteString : public String { | 4074 class ExternalTwoByteString : public AllStatic { |
| 3995 public: | 4075 private: |
| 3996 virtual int32_t CharAt(intptr_t index) const { | 4076 static RawExternalTwoByteString* raw_str(const String& str) { |
| 3997 return *CharAddr(index); | 4077 return reinterpret_cast<RawExternalTwoByteString*>(str.raw_ptr()); |
| 3998 } | 4078 } |
|
siva
2012/11/05 19:23:38
Ditto comment here regarding private method and th
Tom Ball
2012/11/05 21:22:41
Done.
| |
| 3999 | 4079 |
| 4000 virtual intptr_t CharSize() const { | 4080 public: |
| 4001 return kTwoByteChar; | 4081 static int32_t CharAt(const String& str, intptr_t index) { |
| 4082 return *CharAddr(str, index); | |
| 4002 } | 4083 } |
| 4003 | 4084 |
| 4004 virtual bool IsExternal() const { return true; } | 4085 static void* GetPeer(const String& str) { |
| 4005 virtual void* GetPeer() const { | 4086 return raw_str(str)->external_data_->peer(); |
| 4006 return raw_ptr()->external_data_->peer(); | |
| 4007 } | 4087 } |
| 4008 | 4088 |
| 4009 // We use the same maximum elements for all strings. | 4089 // We use the same maximum elements for all strings. |
| 4010 static const intptr_t kBytesPerElement = 2; | 4090 static const intptr_t kBytesPerElement = 2; |
| 4011 static const intptr_t kMaxElements = String::kMaxElements; | 4091 static const intptr_t kMaxElements = String::kMaxElements; |
| 4012 | 4092 |
| 4013 static intptr_t InstanceSize() { | 4093 static intptr_t InstanceSize() { |
| 4014 return RoundedAllocationSize(sizeof(RawExternalTwoByteString)); | 4094 return String::RoundedAllocationSize(sizeof(RawExternalTwoByteString)); |
| 4015 } | 4095 } |
| 4016 | 4096 |
| 4017 static RawExternalTwoByteString* New(const uint16_t* characters, | 4097 static RawExternalTwoByteString* New(const uint16_t* characters, |
| 4018 intptr_t len, | 4098 intptr_t len, |
| 4019 void* peer, | 4099 void* peer, |
| 4020 Dart_PeerFinalizer callback, | 4100 Dart_PeerFinalizer callback, |
| 4021 Heap::Space space = Heap::kNew); | 4101 Heap::Space space = Heap::kNew); |
| 4022 | 4102 |
| 4023 private: | 4103 static RawExternalTwoByteString* null() { |
| 4024 const uint16_t* CharAddr(intptr_t index) const { | 4104 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 } | 4105 } |
| 4029 | 4106 |
| 4030 void SetExternalData(ExternalStringData<uint16_t>* data) { | 4107 static const ClassId kClassId = kExternalTwoByteStringCid; |
| 4031 raw_ptr()->external_data_ = data; | 4108 |
| 4109 private: | |
| 4110 static RawExternalTwoByteString* raw(const String& str) { | |
| 4111 return reinterpret_cast<RawExternalTwoByteString*>(str.raw()); | |
| 4112 } | |
| 4113 | |
| 4114 static const uint16_t* CharAddr(const String& str, intptr_t index) { | |
| 4115 ASSERT((index >= 0) && (index < str.Length())); | |
| 4116 ASSERT(str.IsExternalTwoByteString()); | |
| 4117 NoGCScope no_gc; | |
| 4118 return &(raw_str(str)->external_data_->data()[index]); | |
| 4119 } | |
| 4120 | |
| 4121 static void SetExternalData(const String& str, | |
| 4122 ExternalStringData<uint16_t>* data) { | |
| 4123 ASSERT(str.IsExternalTwoByteString()); | |
| 4124 NoGCScope no_gc; | |
| 4125 raw_str(str)->external_data_ = data; | |
| 4032 } | 4126 } |
| 4033 | 4127 |
| 4034 static void Finalize(Dart_Handle handle, void* peer); | 4128 static void Finalize(Dart_Handle handle, void* peer); |
| 4035 | 4129 |
| 4036 HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString, String); | 4130 static RawExternalTwoByteString* ReadFrom(SnapshotReader* reader, |
| 4131 intptr_t object_id, | |
| 4132 intptr_t tags, | |
| 4133 Snapshot::Kind kind); | |
| 4134 | |
| 4037 friend class Class; | 4135 friend class Class; |
| 4038 friend class String; | 4136 friend class String; |
| 4137 friend class SnapshotReader; | |
| 4039 }; | 4138 }; |
| 4040 | 4139 |
| 4041 | 4140 |
| 4042 // Class Bool implements Dart core class bool. | 4141 // Class Bool implements Dart core class bool. |
| 4043 class Bool : public Instance { | 4142 class Bool : public Instance { |
| 4044 public: | 4143 public: |
| 4045 bool value() const { | 4144 bool value() const { |
| 4046 return raw_ptr()->value_; | 4145 return raw_ptr()->value_; |
| 4047 } | 4146 } |
| 4048 | 4147 |
| (...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5749 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5848 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5750 return false; | 5849 return false; |
| 5751 } | 5850 } |
| 5752 } | 5851 } |
| 5753 return true; | 5852 return true; |
| 5754 } | 5853 } |
| 5755 | 5854 |
| 5756 } // namespace dart | 5855 } // namespace dart |
| 5757 | 5856 |
| 5758 #endif // VM_OBJECT_H_ | 5857 #endif // VM_OBJECT_H_ |
| OLD | NEW |