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 3170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3181 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } | 3181 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
| 3182 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); | 3182 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
| 3183 static intptr_t Hash(const uint8_t* characters, intptr_t len); | 3183 static intptr_t Hash(const uint8_t* characters, intptr_t len); |
| 3184 static intptr_t Hash(const uint16_t* characters, intptr_t len); | 3184 static intptr_t Hash(const uint16_t* characters, intptr_t len); |
| 3185 static intptr_t Hash(const uint32_t* characters, intptr_t len); | 3185 static intptr_t Hash(const uint32_t* characters, intptr_t len); |
| 3186 | 3186 |
| 3187 virtual int32_t CharAt(intptr_t index) const; | 3187 virtual int32_t CharAt(intptr_t index) const; |
| 3188 | 3188 |
| 3189 virtual intptr_t CharSize() const; | 3189 virtual intptr_t CharSize() const; |
| 3190 | 3190 |
| 3191 bool Equals(const String& str) const { | 3191 inline bool Equals(const String& str) const; |
| 3192 if (raw() == str.raw()) { | 3192 inline bool Equals(const String& str, |
| 3193 return true; // Both handles point to the same raw instance. | 3193 intptr_t begin_index, |
| 3194 } | 3194 intptr_t len) const; |
|
srdjan
2012/07/16 20:42:07
Add comment: begin_index of 'str' or 'this'?
siva
2012/07/17 19:15:21
Done.
| |
| 3195 if (str.IsNull()) { | |
| 3196 return false; | |
| 3197 } | |
| 3198 return Equals(str, 0, str.Length()); | |
| 3199 } | |
| 3200 bool Equals(const String& str, intptr_t begin_index, intptr_t len) const; | |
| 3201 bool Equals(const char* str) const; | 3195 bool Equals(const char* str) const; |
| 3202 bool Equals(const uint8_t* characters, intptr_t len) const; | 3196 bool Equals(const uint8_t* characters, intptr_t len) const; |
| 3203 bool Equals(const uint16_t* characters, intptr_t len) const; | 3197 bool Equals(const uint16_t* characters, intptr_t len) const; |
| 3204 bool Equals(const uint32_t* characters, intptr_t len) const; | 3198 bool Equals(const uint32_t* characters, intptr_t len) const; |
| 3205 | 3199 |
| 3206 virtual bool Equals(const Instance& other) const; | 3200 virtual bool Equals(const Instance& other) const; |
| 3207 | 3201 |
| 3208 intptr_t CompareTo(const String& other) const; | 3202 intptr_t CompareTo(const String& other) const; |
| 3209 | 3203 |
| 3210 bool StartsWith(const String& other) const; | 3204 bool StartsWith(const String& other) const; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3333 virtual int32_t CharAt(intptr_t index) const { | 3327 virtual int32_t CharAt(intptr_t index) const { |
| 3334 return *CharAddr(index); | 3328 return *CharAddr(index); |
| 3335 } | 3329 } |
| 3336 | 3330 |
| 3337 virtual intptr_t CharSize() const { | 3331 virtual intptr_t CharSize() const { |
| 3338 return kOneByteChar; | 3332 return kOneByteChar; |
| 3339 } | 3333 } |
| 3340 | 3334 |
| 3341 RawOneByteString* EscapeDoubleQuotes() const; | 3335 RawOneByteString* EscapeDoubleQuotes() const; |
| 3342 | 3336 |
| 3337 bool EqualsIgnoringPrivate(const OneByteString& str) const; | |
|
srdjan
2012/07/16 20:42:07
I think it would be clearer to name it EqualsIgnor
siva
2012/07/17 19:15:21
Done.
| |
| 3338 | |
| 3343 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); } | 3339 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); } |
| 3344 | 3340 |
| 3345 static intptr_t InstanceSize() { | 3341 static intptr_t InstanceSize() { |
| 3346 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); | 3342 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); |
| 3347 return 0; | 3343 return 0; |
| 3348 } | 3344 } |
| 3349 | 3345 |
| 3350 static intptr_t InstanceSize(intptr_t len) { | 3346 static intptr_t InstanceSize(intptr_t len) { |
| 3351 return RoundedAllocationSize(sizeof(RawOneByteString) + len); | 3347 return RoundedAllocationSize(sizeof(RawOneByteString) + len); |
| 3352 } | 3348 } |
| 3353 | 3349 |
| 3354 static RawOneByteString* New(intptr_t len, | 3350 static RawOneByteString* New(intptr_t len, |
| 3355 Heap::Space space); | 3351 Heap::Space space); |
| 3352 static RawOneByteString* New(const char* c_string, | |
| 3353 Heap::Space space = Heap::kNew) { | |
| 3354 return New(reinterpret_cast<const uint8_t*>(c_string), | |
| 3355 strlen(c_string), | |
| 3356 space); | |
| 3357 } | |
| 3356 static RawOneByteString* New(const uint8_t* characters, | 3358 static RawOneByteString* New(const uint8_t* characters, |
| 3357 intptr_t len, | 3359 intptr_t len, |
| 3358 Heap::Space space); | 3360 Heap::Space space); |
| 3359 static RawOneByteString* New(const uint16_t* characters, | 3361 static RawOneByteString* New(const uint16_t* characters, |
| 3360 intptr_t len, | 3362 intptr_t len, |
| 3361 Heap::Space space); | 3363 Heap::Space space); |
| 3362 static RawOneByteString* New(const uint32_t* characters, | 3364 static RawOneByteString* New(const uint32_t* characters, |
| 3363 intptr_t len, | 3365 intptr_t len, |
| 3364 Heap::Space space); | 3366 Heap::Space space); |
| 3365 static RawOneByteString* New(const OneByteString& str, | 3367 static RawOneByteString* New(const OneByteString& str, |
| (...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5131 | 5133 |
| 5132 void Context::SetAt(intptr_t index, const Instance& value) const { | 5134 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 5133 StorePointer(InstanceAddr(index), value.raw()); | 5135 StorePointer(InstanceAddr(index), value.raw()); |
| 5134 } | 5136 } |
| 5135 | 5137 |
| 5136 | 5138 |
| 5137 intptr_t Stackmap::SizeInBits() const { | 5139 intptr_t Stackmap::SizeInBits() const { |
| 5138 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); | 5140 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); |
| 5139 } | 5141 } |
| 5140 | 5142 |
| 5143 | |
| 5144 bool String::Equals(const String& str) const { | |
| 5145 if (raw() == str.raw()) { | |
| 5146 return true; // Both handles point to the same raw instance. | |
| 5147 } | |
| 5148 if (str.IsNull()) { | |
| 5149 return false; | |
| 5150 } | |
| 5151 return Equals(str, 0, str.Length()); | |
| 5152 } | |
| 5153 | |
| 5154 | |
| 5155 bool String::Equals(const String& str, | |
| 5156 intptr_t begin_index, | |
| 5157 intptr_t len) const { | |
| 5158 ASSERT(begin_index >= 0); | |
| 5159 ASSERT((begin_index == 0) || (begin_index < str.Length())); | |
| 5160 ASSERT(len >= 0); | |
| 5161 ASSERT(len <= str.Length()); | |
| 5162 if (len != this->Length()) { | |
| 5163 return false; // Lengths don't match. | |
| 5164 } | |
| 5165 for (intptr_t i = 0; i < len; i++) { | |
| 5166 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | |
| 5167 return false; | |
| 5168 } | |
| 5169 } | |
| 5170 return true; | |
| 5171 } | |
| 5172 | |
| 5141 } // namespace dart | 5173 } // namespace dart |
| 5142 | 5174 |
| 5143 #endif // VM_OBJECT_H_ | 5175 #endif // VM_OBJECT_H_ |
| OLD | NEW |