Chromium Code Reviews| Index: runtime/vm/object.h |
| diff --git a/runtime/vm/object.h b/runtime/vm/object.h |
| index f924e7a3021080c88c410f8cf4307728fdfb7cec..008a50a57cee0f629cb447b516311e265f706c75 100644 |
| --- a/runtime/vm/object.h |
| +++ b/runtime/vm/object.h |
| @@ -3643,9 +3643,9 @@ class String : public Instance { |
| static intptr_t Hash(const uint16_t* characters, intptr_t len); |
| static intptr_t Hash(const uint32_t* characters, intptr_t len); |
| - virtual int32_t CharAt(intptr_t index) const; |
| + int32_t CharAt(intptr_t index) const; |
| - virtual intptr_t CharSize() const; |
| + intptr_t CharSize() const; |
| inline bool Equals(const String& str) const; |
| inline bool Equals(const String& str, |
| @@ -3666,12 +3666,26 @@ class String : public Instance { |
| bool IsSymbol() const { return raw()->IsCanonical(); } |
| - virtual bool IsExternal() const { return false; } |
| - virtual void* GetPeer() const { |
| - UNREACHABLE(); |
| - return NULL; |
| + bool IsOneByteString() const { |
| + return raw()->GetClassId() == kOneByteStringCid; |
| + } |
| + |
| + bool IsTwoByteString() const { |
| + return raw()->GetClassId() == kTwoByteStringCid; |
| + } |
| + |
| + bool IsExternalOneByteString() const { |
| + return raw()->GetClassId() == kExternalOneByteStringCid; |
| + } |
| + |
| + bool IsExternalTwoByteString() const { |
| + return raw()->GetClassId() == kExternalTwoByteStringCid; |
| } |
| + bool IsExternal() const; |
|
siva
2012/11/02 01:15:25
why not inline this too:
{
return IsExternalOneB
Tom Ball
2012/11/02 23:31:50
Good idea -- I also found that RawObject::IsExtern
|
| + |
| + void* GetPeer() const; |
| + |
| void ToUTF8(uint8_t* utf8_array, intptr_t array_len) const; |
| // Creates a new String object from a C string that is assumed to contain |
| @@ -3775,7 +3789,7 @@ class String : public Instance { |
| template<typename HandleType, typename ElementType> |
| static void ReadFromImpl(SnapshotReader* reader, |
| - HandleType* str_obj, |
| + String* str_obj, |
| intptr_t len, |
| intptr_t tags, |
| Snapshot::Kind kind); |
| @@ -3783,22 +3797,24 @@ class String : public Instance { |
| HEAP_OBJECT_IMPLEMENTATION(String, Instance); |
| friend class Symbols; |
| + friend class OneByteString; |
| + friend class TwoByteString; |
| + friend class ExternalOneByteString; |
| + friend class ExternalTwoByteString; |
| }; |
| class OneByteString : public String { |
|
siva
2012/11/02 01:15:25
We does this have to inherit from String
Shouldn'
Tom Ball
2012/11/02 23:31:50
Done.
|
| public: |
| - virtual int32_t CharAt(intptr_t index) const { |
| - return *CharAddr(index); |
| - } |
| - |
| - virtual intptr_t CharSize() const { |
| - return kOneByteChar; |
| + static int32_t CharAt(const String& str, intptr_t index) { |
| + return *CharAddr(str, index); |
| } |
| - RawOneByteString* EscapeSpecialCharacters(bool raw_str) const; |
| + static RawOneByteString* EscapeSpecialCharacters(const String& str, |
| + bool raw_str); |
| - bool EqualsIgnoringPrivateKey(const OneByteString& str) const; |
| + static bool EqualsIgnoringPrivateKey(const String& str1, |
| + const String& str2); |
| // We use the same maximum elements for all strings. |
| static const intptr_t kBytesPerElement = 1; |
| @@ -3849,14 +3865,25 @@ class OneByteString : public String { |
| const String& str, |
| Heap::Space space); |
| + static RawOneByteString* ReadFrom(SnapshotReader* reader, |
| + intptr_t object_id, |
| + intptr_t tags, |
| + Snapshot::Kind kind); |
|
siva
2012/11/02 01:15:25
Why is this a public method for all other classes
Tom Ball
2012/11/02 23:31:50
Made private for all four string classes.
|
| + |
| + static const ClassId kClassId = kOneByteStringCid; |
| + |
| + static RawOneByteString* null() { |
| + return reinterpret_cast<RawOneByteString*>(Object::null()); |
| + } |
| + |
| private: |
| - uint8_t* CharAddr(intptr_t index) const { |
| - // TODO(iposva): Determine if we should throw an exception here. |
| - ASSERT((index >= 0) && (index < Length())); |
| - return &raw_ptr()->data_[index]; |
| + static uint8_t* CharAddr(const String& str, intptr_t index) { |
|
siva
2012/11/02 01:15:25
The index assertion seems to have been dropped..
Tom Ball
2012/11/02 23:31:50
Restored old assertion and added new one.
|
| + NoGCScope no_gc; |
| + RawOneByteString* raw_str = |
| + reinterpret_cast<RawOneByteString*>(str.raw_ptr()); |
| + return &raw_str->data_[index]; |
| } |
| - HEAP_OBJECT_IMPLEMENTATION(OneByteString, String); |
| friend class Class; |
| friend class String; |
| }; |
| @@ -3864,15 +3891,12 @@ class OneByteString : public String { |
| class TwoByteString : public String { |
|
siva
2012/11/02 01:15:25
Ditto comment about this inheriting from String.
S
Tom Ball
2012/11/02 23:31:50
Done.
|
| public: |
| - virtual int32_t CharAt(intptr_t index) const { |
| - return *CharAddr(index); |
| - } |
| - |
| - virtual intptr_t CharSize() const { |
| - return kTwoByteChar; |
| + static int32_t CharAt(const String& str, intptr_t index) { |
| + return *CharAddr(str, index); |
| } |
| - RawTwoByteString* EscapeSpecialCharacters(bool raw_str) const; |
| + static RawTwoByteString* EscapeSpecialCharacters(const String& str, |
| + bool raw_str); |
| // We use the same maximum elements for all strings. |
| static const intptr_t kBytesPerElement = 2; |
| @@ -3913,31 +3937,43 @@ class TwoByteString : public String { |
| const String& str, |
| Heap::Space space); |
| + static RawTwoByteString* ReadFrom(SnapshotReader* reader, |
| + intptr_t object_id, |
| + intptr_t tags, |
| + Snapshot::Kind kind); |
|
siva
2012/11/02 01:15:25
Ditto comment about this being a public method.
Tom Ball
2012/11/02 23:31:50
Done.
|
| + |
| + static RawTwoByteString* null() { |
| + return reinterpret_cast<RawTwoByteString*>(Object::null()); |
| + } |
| + |
| + static const ClassId kClassId = kTwoByteStringCid; |
| + |
| private: |
| - uint16_t* CharAddr(intptr_t index) const { |
| - ASSERT((index >= 0) && (index < Length())); |
| - return &raw_ptr()->data_[index]; |
| + static uint16_t* CharAddr(const String& str, intptr_t index) { |
|
siva
2012/11/02 01:15:25
The index assertion seems to have been dropped.
A
Tom Ball
2012/11/02 23:31:50
Done.
|
| + NoGCScope no_gc; |
| + RawTwoByteString* raw_str = |
| + reinterpret_cast<RawTwoByteString*>(str.raw_ptr()); |
| + return &raw_str->data_[index]; |
| } |
| - HEAP_OBJECT_IMPLEMENTATION(TwoByteString, String); |
| friend class Class; |
| friend class String; |
| }; |
| class ExternalOneByteString : public String { |
|
siva
2012/11/02 01:15:25
Ditto comment about inheriting from String, should
Tom Ball
2012/11/02 23:31:50
Done.
|
| - public: |
| - virtual int32_t CharAt(intptr_t index) const { |
| - return *CharAddr(index); |
| + private: |
| + static RawExternalOneByteString* raw_str(const String& str) { |
| + return reinterpret_cast<RawExternalOneByteString*>(str.raw_ptr()); |
| } |
| - virtual intptr_t CharSize() const { |
| - return kOneByteChar; |
| + public: |
| + static int32_t CharAt(const String& str, intptr_t index) { |
| + return *CharAddr(str, index); |
| } |
| - virtual bool IsExternal() const { return true; } |
| - virtual void* GetPeer() const { |
| - return raw_ptr()->external_data_->peer(); |
| + static void* GetPeer(const String& str) { |
| + return raw_str(str)->external_data_->peer(); |
| } |
| // We use the same maximum elements for all strings. |
| @@ -3954,38 +3990,50 @@ class ExternalOneByteString : public String { |
| Dart_PeerFinalizer callback, |
| Heap::Space space); |
| + static RawExternalOneByteString* ReadFrom(SnapshotReader* reader, |
| + intptr_t object_id, |
| + intptr_t tags, |
| + Snapshot::Kind kind); |
|
siva
2012/11/02 01:15:25
Ditto comment about this being a public method.
Tom Ball
2012/11/02 23:31:50
Done.
|
| + |
| + static RawExternalOneByteString* null() { |
| + return reinterpret_cast<RawExternalOneByteString*>(Object::null()); |
| + } |
| + |
| + static const ClassId kClassId = kExternalOneByteStringCid; |
| + |
| private: |
| - const uint8_t* CharAddr(intptr_t index) const { |
| - // TODO(iposva): Determine if we should throw an exception here. |
| - ASSERT((index >= 0) && (index < Length())); |
| - return &(raw_ptr()->external_data_->data()[index]); |
| + static const uint8_t* CharAddr(const String& str, intptr_t index) { |
| + ASSERT((index >= 0) && (index < str.Length())); |
|
siva
2012/11/02 01:15:25
ASSERT(str.IsExternalOneByteString());
Tom Ball
2012/11/02 23:31:50
Done.
|
| + NoGCScope no_gc; |
| + return &(raw_str(str)->external_data_->data()[index]); |
| } |
| - void SetExternalData(ExternalStringData<uint8_t>* data) { |
| - raw_ptr()->external_data_ = data; |
| + static void SetExternalData(const String& str, |
| + ExternalStringData<uint8_t>* data) { |
|
siva
2012/11/02 01:15:25
ASSERT(str.IsExternalOneByteString());
Tom Ball
2012/11/02 23:31:50
Done.
|
| + NoGCScope no_gc; |
| + raw_str(str)->external_data_ = data; |
| } |
| static void Finalize(Dart_Handle handle, void* peer); |
| - HEAP_OBJECT_IMPLEMENTATION(ExternalOneByteString, String); |
| friend class Class; |
| friend class String; |
| }; |
| class ExternalTwoByteString : public String { |
|
siva
2012/11/02 01:15:25
Ditto comment about inheriting from AllStatic not
Tom Ball
2012/11/02 23:31:50
Done.
|
| - public: |
| - virtual int32_t CharAt(intptr_t index) const { |
| - return *CharAddr(index); |
| + private: |
| + static RawExternalTwoByteString* raw_str(const String& str) { |
| + return reinterpret_cast<RawExternalTwoByteString*>(str.raw_ptr()); |
| } |
| - virtual intptr_t CharSize() const { |
| - return kTwoByteChar; |
| + public: |
| + static int32_t CharAt(const String& str, intptr_t index) { |
| + return *CharAddr(str, index); |
| } |
| - virtual bool IsExternal() const { return true; } |
| - virtual void* GetPeer() const { |
| - return raw_ptr()->external_data_->peer(); |
| + static void* GetPeer(const String& str) { |
| + return raw_str(str)->external_data_->peer(); |
| } |
| // We use the same maximum elements for all strings. |
| @@ -4002,20 +4050,31 @@ class ExternalTwoByteString : public String { |
| Dart_PeerFinalizer callback, |
| Heap::Space space = Heap::kNew); |
| + static RawExternalTwoByteString* ReadFrom(SnapshotReader* reader, |
| + intptr_t object_id, |
| + intptr_t tags, |
| + Snapshot::Kind kind); |
|
siva
2012/11/02 01:15:25
Ditto comment about being public.
Tom Ball
2012/11/02 23:31:50
Done.
|
| + |
| + static RawExternalTwoByteString* null() { |
| + return reinterpret_cast<RawExternalTwoByteString*>(Object::null()); |
| + } |
| + |
| + static const ClassId kClassId = kExternalTwoByteStringCid; |
| + |
| private: |
| - const uint16_t* CharAddr(intptr_t index) const { |
| - // TODO(iposva): Determine if we should throw an exception here. |
| - ASSERT((index >= 0) && (index < Length())); |
| - return &(raw_ptr()->external_data_->data()[index]); |
| + static const uint16_t* CharAddr(const String& str, intptr_t index) { |
| + ASSERT((index >= 0) && (index < str.Length())); |
|
siva
2012/11/02 01:15:25
ASSERT(str.IsExternalTwoByteString());
Tom Ball
2012/11/02 23:31:50
Done.
|
| + NoGCScope no_gc; |
| + return &(raw_str(str)->external_data_->data()[index]); |
| } |
| - void SetExternalData(ExternalStringData<uint16_t>* data) { |
| - raw_ptr()->external_data_ = data; |
| + static void SetExternalData(const String& str, |
| + ExternalStringData<uint16_t>* data) { |
|
siva
2012/11/02 01:15:25
ASSERT(str.IsExternalTwoByteString());
NoGCScope n
Tom Ball
2012/11/02 23:31:50
Done.
|
| + raw_str(str)->external_data_ = data; |
| } |
| static void Finalize(Dart_Handle handle, void* peer); |
| - HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString, String); |
| friend class Class; |
| friend class String; |
| }; |