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" |
| 11 #include "vm/bitmap.h" | 11 #include "vm/bitmap.h" |
| 12 #include "vm/dart.h" | 12 #include "vm/dart.h" |
| 13 #include "vm/globals.h" | 13 #include "vm/globals.h" |
| 14 #include "vm/handles.h" | 14 #include "vm/handles.h" |
| 15 #include "vm/heap.h" | 15 #include "vm/heap.h" |
| 16 #include "vm/isolate.h" | 16 #include "vm/isolate.h" |
| 17 #include "vm/os.h" | 17 #include "vm/os.h" |
| 18 #include "vm/raw_object.h" | 18 #include "vm/raw_object.h" |
| 19 #include "vm/scanner.h" | 19 #include "vm/scanner.h" |
| 20 #include "vm/unicode.h" | |
| 20 | 21 |
| 21 namespace dart { | 22 namespace dart { |
| 22 | 23 |
| 23 // Forward declarations. | 24 // Forward declarations. |
| 24 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 25 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
| 25 class clazz; | 26 class clazz; |
| 26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 27 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
| 27 #undef DEFINE_FORWARD_DECLARATION | 28 #undef DEFINE_FORWARD_DECLARATION |
| 28 class Api; | 29 class Api; |
| 29 class Assembler; | 30 class Assembler; |
| (...skipping 3647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3677 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } | 3678 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } |
| 3678 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } | 3679 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } |
| 3679 | 3680 |
| 3680 virtual intptr_t Hash() const; | 3681 virtual intptr_t Hash() const; |
| 3681 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } | 3682 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
| 3682 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); | 3683 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
| 3683 static intptr_t Hash(const uint8_t* characters, intptr_t len); | 3684 static intptr_t Hash(const uint8_t* characters, intptr_t len); |
| 3684 static intptr_t Hash(const uint16_t* characters, intptr_t len); | 3685 static intptr_t Hash(const uint16_t* characters, intptr_t len); |
| 3685 static intptr_t Hash(const uint32_t* characters, intptr_t len); | 3686 static intptr_t Hash(const uint32_t* characters, intptr_t len); |
| 3686 | 3687 |
| 3687 int32_t CharAt(intptr_t index) const; | 3688 uint32_t CharAt(intptr_t index) const; |
| 3689 uint32_t CodeUnitAt(intptr_t index) const; | |
| 3688 | 3690 |
| 3689 intptr_t CharSize() const; | 3691 intptr_t CharSize() const; |
| 3690 | 3692 |
| 3691 inline bool Equals(const String& str) const; | 3693 inline bool Equals(const String& str) const; |
| 3692 inline bool Equals(const String& str, | 3694 inline bool Equals(const String& str, |
| 3693 intptr_t begin_index, // begin index on 'str'. | 3695 intptr_t begin_index, // begin index on 'str'. |
| 3694 intptr_t len) const; // len on 'str'. | 3696 intptr_t len) const; // len on 'str'. |
| 3695 bool Equals(const char* str) const; | 3697 bool Equals(const char* str) const; |
| 3696 bool Equals(const uint8_t* characters, intptr_t len) const; | 3698 bool Equals(const uint8_t* characters, intptr_t len) const; |
| 3697 bool Equals(const uint16_t* characters, intptr_t len) const; | 3699 bool Equals(const uint16_t* characters, intptr_t len) const; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3843 friend class Symbols; | 3845 friend class Symbols; |
| 3844 friend class OneByteString; | 3846 friend class OneByteString; |
| 3845 friend class TwoByteString; | 3847 friend class TwoByteString; |
| 3846 friend class ExternalOneByteString; | 3848 friend class ExternalOneByteString; |
| 3847 friend class ExternalTwoByteString; | 3849 friend class ExternalTwoByteString; |
| 3848 }; | 3850 }; |
| 3849 | 3851 |
| 3850 | 3852 |
| 3851 class OneByteString : public AllStatic { | 3853 class OneByteString : public AllStatic { |
| 3852 public: | 3854 public: |
| 3853 static int32_t CharAt(const String& str, intptr_t index) { | 3855 static uint32_t CharAt(const String& str, intptr_t index) { |
| 3854 return *CharAddr(str, index); | 3856 return *CharAddr(str, index); |
| 3855 } | 3857 } |
| 3856 | 3858 |
| 3859 static uint32_t CodeUnitAt(const String& str, intptr_t index) { | |
| 3860 return *CharAddr(str, index); | |
| 3861 } | |
| 3862 | |
| 3857 static RawOneByteString* EscapeSpecialCharacters(const String& str, | 3863 static RawOneByteString* EscapeSpecialCharacters(const String& str, |
| 3858 bool raw_str); | 3864 bool raw_str); |
| 3859 | 3865 |
| 3860 static bool EqualsIgnoringPrivateKey(const String& str1, | 3866 static bool EqualsIgnoringPrivateKey(const String& str1, |
| 3861 const String& str2); | 3867 const String& str2); |
| 3862 | 3868 |
| 3863 // We use the same maximum elements for all strings. | 3869 // We use the same maximum elements for all strings. |
| 3864 static const intptr_t kBytesPerElement = 1; | 3870 static const intptr_t kBytesPerElement = 1; |
| 3865 static const intptr_t kMaxElements = String::kMaxElements; | 3871 static const intptr_t kMaxElements = String::kMaxElements; |
| 3866 | 3872 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3900 | 3906 |
| 3901 static RawOneByteString* Concat(const String& str1, | 3907 static RawOneByteString* Concat(const String& str1, |
| 3902 const String& str2, | 3908 const String& str2, |
| 3903 Heap::Space space); | 3909 Heap::Space space); |
| 3904 static RawOneByteString* ConcatAll(const Array& strings, | 3910 static RawOneByteString* ConcatAll(const Array& strings, |
| 3905 intptr_t len, | 3911 intptr_t len, |
| 3906 Heap::Space space); | 3912 Heap::Space space); |
| 3907 | 3913 |
| 3908 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), | 3914 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), |
| 3909 const String& str, | 3915 const String& str, |
| 3916 int out_length, | |
| 3910 Heap::Space space); | 3917 Heap::Space space); |
| 3911 | 3918 |
| 3912 static const ClassId kClassId = kOneByteStringCid; | 3919 static const ClassId kClassId = kOneByteStringCid; |
| 3913 | 3920 |
| 3914 static RawOneByteString* null() { | 3921 static RawOneByteString* null() { |
| 3915 return reinterpret_cast<RawOneByteString*>(Object::null()); | 3922 return reinterpret_cast<RawOneByteString*>(Object::null()); |
| 3916 } | 3923 } |
| 3917 | 3924 |
| 3918 private: | 3925 private: |
| 3919 static RawOneByteString* raw(const String& str) { | 3926 static RawOneByteString* raw(const String& str) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 3937 Snapshot::Kind kind); | 3944 Snapshot::Kind kind); |
| 3938 | 3945 |
| 3939 friend class Class; | 3946 friend class Class; |
| 3940 friend class String; | 3947 friend class String; |
| 3941 friend class SnapshotReader; | 3948 friend class SnapshotReader; |
| 3942 }; | 3949 }; |
| 3943 | 3950 |
| 3944 | 3951 |
| 3945 class TwoByteString : public AllStatic { | 3952 class TwoByteString : public AllStatic { |
| 3946 public: | 3953 public: |
| 3947 static int32_t CharAt(const String& str, intptr_t index) { | 3954 static uint32_t CharAt(const String& str, intptr_t index) { |
| 3955 int32_t unit = *CharAddr(str, index); | |
| 3956 // For non-surrogate values or incorrect trailing surrogates we just return | |
| 3957 // the value. | |
| 3958 if (!Utf16::IsLeadSurrogate(unit)) return unit; | |
| 3959 | |
| 3960 // If the string ends with a lead surrogate we just return that. | |
| 3961 if (index + 1 >= str.Length()) return unit; | |
| 3962 | |
| 3963 return Utf16::CodePointFromCodeUnits(unit, *CharAddr(str, index + 1)); | |
| 3964 } | |
| 3965 | |
| 3966 static uint32_t CodeUnitAt(const String& str, intptr_t index) { | |
| 3948 return *CharAddr(str, index); | 3967 return *CharAddr(str, index); |
| 3949 } | 3968 } |
|
siva
2012/11/08 19:06:47
I don't mind changing the name 'CharAt' to 'CodeU
erikcorry
2012/11/08 22:09:34
Do you want to move the C++ support for toUpperCas
siva
2012/11/09 02:40:42
We could fix String::Transform/TwoByteString::Tran
erikcorry
2012/11/15 13:28:25
I have fixed the UTF8 and the Transform (toUpper/L
| |
| 3950 | 3969 |
| 3951 static RawTwoByteString* EscapeSpecialCharacters(const String& str, | 3970 static RawTwoByteString* EscapeSpecialCharacters(const String& str, |
| 3952 bool raw_str); | 3971 bool raw_str); |
| 3953 | 3972 |
| 3954 // We use the same maximum elements for all strings. | 3973 // We use the same maximum elements for all strings. |
| 3955 static const intptr_t kBytesPerElement = 2; | 3974 static const intptr_t kBytesPerElement = 2; |
| 3956 static const intptr_t kMaxElements = String::kMaxElements; | 3975 static const intptr_t kMaxElements = String::kMaxElements; |
| 3957 | 3976 |
| 3958 static intptr_t data_offset() { return OFFSET_OF(RawTwoByteString, data_); } | 3977 static intptr_t data_offset() { return OFFSET_OF(RawTwoByteString, data_); } |
| 3959 | 3978 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 3983 | 4002 |
| 3984 static RawTwoByteString* Concat(const String& str1, | 4003 static RawTwoByteString* Concat(const String& str1, |
| 3985 const String& str2, | 4004 const String& str2, |
| 3986 Heap::Space space); | 4005 Heap::Space space); |
| 3987 static RawTwoByteString* ConcatAll(const Array& strings, | 4006 static RawTwoByteString* ConcatAll(const Array& strings, |
| 3988 intptr_t len, | 4007 intptr_t len, |
| 3989 Heap::Space space); | 4008 Heap::Space space); |
| 3990 | 4009 |
| 3991 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), | 4010 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), |
| 3992 const String& str, | 4011 const String& str, |
| 4012 int out_length, | |
| 3993 Heap::Space space); | 4013 Heap::Space space); |
| 3994 | 4014 |
| 3995 static RawTwoByteString* null() { | 4015 static RawTwoByteString* null() { |
| 3996 return reinterpret_cast<RawTwoByteString*>(Object::null()); | 4016 return reinterpret_cast<RawTwoByteString*>(Object::null()); |
| 3997 } | 4017 } |
| 3998 | 4018 |
| 3999 | 4019 |
| 4000 static const ClassId kClassId = kTwoByteStringCid; | 4020 static const ClassId kClassId = kTwoByteStringCid; |
| 4001 | 4021 |
| 4002 private: | 4022 private: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 4021 Snapshot::Kind kind); | 4041 Snapshot::Kind kind); |
| 4022 | 4042 |
| 4023 friend class Class; | 4043 friend class Class; |
| 4024 friend class String; | 4044 friend class String; |
| 4025 friend class SnapshotReader; | 4045 friend class SnapshotReader; |
| 4026 }; | 4046 }; |
| 4027 | 4047 |
| 4028 | 4048 |
| 4029 class ExternalOneByteString : public AllStatic { | 4049 class ExternalOneByteString : public AllStatic { |
| 4030 public: | 4050 public: |
| 4031 static int32_t CharAt(const String& str, intptr_t index) { | 4051 static uint32_t CharAt(const String& str, intptr_t index) { |
| 4032 return *CharAddr(str, index); | 4052 return *CharAddr(str, index); |
| 4033 } | 4053 } |
| 4034 | 4054 |
| 4055 static uint32_t CodeUnitAt(const String& str, intptr_t index) { | |
| 4056 return *CharAddr(str, index); | |
| 4057 } | |
| 4058 | |
| 4035 static void* GetPeer(const String& str) { | 4059 static void* GetPeer(const String& str) { |
| 4036 return raw_ptr(str)->external_data_->peer(); | 4060 return raw_ptr(str)->external_data_->peer(); |
| 4037 } | 4061 } |
| 4038 | 4062 |
| 4039 // We use the same maximum elements for all strings. | 4063 // We use the same maximum elements for all strings. |
| 4040 static const intptr_t kBytesPerElement = 1; | 4064 static const intptr_t kBytesPerElement = 1; |
| 4041 static const intptr_t kMaxElements = String::kMaxElements; | 4065 static const intptr_t kMaxElements = String::kMaxElements; |
| 4042 | 4066 |
| 4043 static intptr_t InstanceSize() { | 4067 static intptr_t InstanceSize() { |
| 4044 return String::RoundedAllocationSize(sizeof(RawExternalOneByteString)); | 4068 return String::RoundedAllocationSize(sizeof(RawExternalOneByteString)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4087 Snapshot::Kind kind); | 4111 Snapshot::Kind kind); |
| 4088 | 4112 |
| 4089 friend class Class; | 4113 friend class Class; |
| 4090 friend class String; | 4114 friend class String; |
| 4091 friend class SnapshotReader; | 4115 friend class SnapshotReader; |
| 4092 }; | 4116 }; |
| 4093 | 4117 |
| 4094 | 4118 |
| 4095 class ExternalTwoByteString : public AllStatic { | 4119 class ExternalTwoByteString : public AllStatic { |
| 4096 public: | 4120 public: |
| 4097 static int32_t CharAt(const String& str, intptr_t index) { | 4121 static uint32_t CharAt(const String& str, intptr_t index) { |
| 4122 int32_t unit = *CharAddr(str, index); | |
|
floitsch
2012/11/08 15:28:21
uint32_t unit =
erikcorry
2012/11/15 13:28:25
This code is gone.
| |
| 4123 // For non-surrogate values or incorrect trailing surrogates we just return | |
| 4124 // the value. | |
| 4125 if (!Utf16::IsLeadSurrogate(unit)) return unit; | |
| 4126 | |
| 4127 // If the string ends with a lead surrogate we just return that. | |
| 4128 if (index + 1 >= str.Length()) return unit; | |
| 4129 | |
| 4130 return Utf16::CodePointFromCodeUnits(unit, *CharAddr(str, index + 1)); | |
| 4131 } | |
| 4132 | |
| 4133 static uint32_t CodeUnitAt(const String& str, intptr_t index) { | |
| 4098 return *CharAddr(str, index); | 4134 return *CharAddr(str, index); |
| 4099 } | 4135 } |
| 4100 | 4136 |
| 4101 static void* GetPeer(const String& str) { | 4137 static void* GetPeer(const String& str) { |
| 4102 return raw_ptr(str)->external_data_->peer(); | 4138 return raw_ptr(str)->external_data_->peer(); |
| 4103 } | 4139 } |
| 4104 | 4140 |
| 4105 // We use the same maximum elements for all strings. | 4141 // We use the same maximum elements for all strings. |
| 4106 static const intptr_t kBytesPerElement = 2; | 4142 static const intptr_t kBytesPerElement = 2; |
| 4107 static const intptr_t kMaxElements = String::kMaxElements; | 4143 static const intptr_t kMaxElements = String::kMaxElements; |
| (...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5851 intptr_t begin_index, | 5887 intptr_t begin_index, |
| 5852 intptr_t len) const { | 5888 intptr_t len) const { |
| 5853 ASSERT(begin_index >= 0); | 5889 ASSERT(begin_index >= 0); |
| 5854 ASSERT((begin_index == 0) || (begin_index < str.Length())); | 5890 ASSERT((begin_index == 0) || (begin_index < str.Length())); |
| 5855 ASSERT(len >= 0); | 5891 ASSERT(len >= 0); |
| 5856 ASSERT(len <= str.Length()); | 5892 ASSERT(len <= str.Length()); |
| 5857 if (len != this->Length()) { | 5893 if (len != this->Length()) { |
| 5858 return false; // Lengths don't match. | 5894 return false; // Lengths don't match. |
| 5859 } | 5895 } |
| 5860 for (intptr_t i = 0; i < len; i++) { | 5896 for (intptr_t i = 0; i < len; i++) { |
| 5861 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5897 if (this->CodeUnitAt(i) != str.CodeUnitAt(begin_index + i)) { |
| 5862 return false; | 5898 return false; |
| 5863 } | 5899 } |
| 5864 } | 5900 } |
| 5865 return true; | 5901 return true; |
| 5866 } | 5902 } |
| 5867 | 5903 |
| 5868 } // namespace dart | 5904 } // namespace dart |
| 5869 | 5905 |
| 5870 #endif // VM_OBJECT_H_ | 5906 #endif // VM_OBJECT_H_ |
| OLD | NEW |