Chromium Code Reviews| Index: src/objects.h |
| diff --git a/src/objects.h b/src/objects.h |
| index 9ef14dbdab6868ed3f2e5461b02be1351dc8f597..8acf9636703e9a4ecbe0d32a63b546838dc0aa69 100644 |
| --- a/src/objects.h |
| +++ b/src/objects.h |
| @@ -86,6 +86,7 @@ |
| // - SeqString |
| // - SeqAsciiString |
| // - SeqTwoByteString |
| +// - SlicedString |
| // - ConsString |
| // - ExternalString |
| // - ExternalAsciiString |
| @@ -280,6 +281,7 @@ static const int kVariableSizeSentinel = 0; |
| V(ASCII_STRING_TYPE) \ |
| V(CONS_STRING_TYPE) \ |
| V(CONS_ASCII_STRING_TYPE) \ |
| + V(SLICED_STRING_TYPE) \ |
| V(EXTERNAL_STRING_TYPE) \ |
| V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
| V(EXTERNAL_ASCII_STRING_TYPE) \ |
| @@ -396,6 +398,14 @@ static const int kVariableSizeSentinel = 0; |
| ConsString::kSize, \ |
| cons_ascii_string, \ |
| ConsAsciiString) \ |
| + V(SLICED_STRING_TYPE, \ |
| + SlicedString::kSize, \ |
| + sliced_string, \ |
| + SlicedString) \ |
| + V(SLICED_ASCII_STRING_TYPE, \ |
| + SlicedString::kSize, \ |
| + sliced_ascii_string, \ |
| + SlicedAsciiString) \ |
| V(EXTERNAL_STRING_TYPE, \ |
| ExternalTwoByteString::kSize, \ |
| external_string, \ |
| @@ -469,9 +479,15 @@ const uint32_t kStringRepresentationMask = 0x03; |
| enum StringRepresentationTag { |
| kSeqStringTag = 0x0, |
| kConsStringTag = 0x1, |
| - kExternalStringTag = 0x2 |
| + kExternalStringTag = 0x2, |
| + kSlicedStringTag = 0x3 |
| }; |
| -const uint32_t kIsConsStringMask = 0x1; |
| +const uint32_t kIsIndirectStringMask = 0x1; |
| +const uint32_t kIsIndirectStringTag = 0x1; |
| +STATIC_ASSERT( |
| + (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
| +STATIC_ASSERT( |
| + (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
| // If bit 7 is clear, then bit 3 indicates whether this two-byte |
| // string actually contains ascii data. |
| @@ -506,6 +522,8 @@ enum InstanceType { |
| ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
| CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
| CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
| + SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, |
| + SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag, |
| EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
| @@ -709,6 +727,7 @@ class MaybeObject BASE_EMBEDDED { |
| V(SeqString) \ |
| V(ExternalString) \ |
| V(ConsString) \ |
| + V(SlicedString) \ |
| V(ExternalTwoByteString) \ |
| V(ExternalAsciiString) \ |
| V(SeqTwoByteString) \ |
| @@ -5709,6 +5728,8 @@ class StringShape BASE_EMBEDDED { |
| inline bool IsSequential(); |
| inline bool IsExternal(); |
| inline bool IsCons(); |
| + inline bool IsSliced(); |
| + inline bool IsIndirect(); |
| inline bool IsExternalAscii(); |
| inline bool IsExternalTwoByte(); |
| inline bool IsSequentialAscii(); |
| @@ -5794,6 +5815,18 @@ class String: public HeapObject { |
| // string. |
| inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| + // Equivalent to Flatten for string slices. A new parent string is created |
| + // with exactly the required characters. Offset is set to 0. |
| + inline MaybeObject* TryTruncate(PretenureFlag pretenure = NOT_TENURED); |
| + inline String* TryTruncateGetString(PretenureFlag pretenure = NOT_TENURED); |
| + |
| + // Combines flatten and truncate. |
| + inline MaybeObject* TryFlattenOrTruncate(PretenureFlag pretenure |
| + = NOT_TENURED); |
| + |
| + // Returns the parent of a sliced string or first part of a cons string. |
| + inline String* GetIndirect(); |
| + |
| Vector<const char> ToAsciiVector(); |
| Vector<const uc16> ToUC16Vector(); |
| @@ -5881,6 +5914,8 @@ class String: public HeapObject { |
| void StringVerify(); |
| #endif |
| inline bool IsFlat(); |
| + inline bool IsTruncated(); |
| + inline bool IsFlatAndTruncated(); |
| // Layout description. |
| static const int kLengthOffset = HeapObject::kHeaderSize; |
| @@ -6043,6 +6078,11 @@ class String: public HeapObject { |
| // mutates the ConsString and might return a failure. |
| MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
| + // Try to create a new sequential string as parent for the slice that is |
| + // as short as possible. This is a no-op unless the string is a SlicedString. |
| + // Truncating mutates the SlicedString and might return a failure. |
| + MUST_USE_RESULT MaybeObject* SlowTryTruncate(PretenureFlag pretenure); |
| + |
| static inline bool IsHashFieldComputed(uint32_t field); |
| // Slow case of String::Equals. This implementation works on any strings |
| @@ -6223,11 +6263,57 @@ class ConsString: public String { |
| typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| BodyDescriptor; |
| +#ifdef DEBUG |
| + void ConsStringVerify(); |
| +#endif |
| + |
| private: |
| DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| }; |
| +class SlicedString: public String { |
|
Vitaly Repeshko
2011/08/05 12:14:14
Please document classes. Explain that only slices
|
| + public: |
| + |
| + inline String* parent(); |
| + inline void set_parent(String* parent); |
| + inline int offset(); |
| + inline void set_offset(int offset); |
| + |
| + // Dispatched behavior. |
| + uint16_t SlicedStringGet(int index); |
| + |
| + // Casting. |
| + static inline SlicedString* cast(Object* obj); |
| + |
| + // Layout description. |
| + static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); |
| + static const int kOffsetOffset = kParentOffset + kPointerSize; |
| + static const int kSize = kOffsetOffset + kPointerSize; |
| + |
| + // Support for StringInputBuffer |
| + inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer, |
| + unsigned* offset_ptr, |
| + unsigned chars); |
| + inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| + unsigned* offset_ptr, |
| + unsigned chars); |
| + // Minimum length for a sliced string. |
| + static const int kMinLength = 13; |
| + |
| + typedef FixedBodyDescriptor<kParentOffset, |
| + kOffsetOffset + kPointerSize, kSize> |
| + BodyDescriptor; |
| + |
| +#ifdef DEBUG |
| + void SlicedStringVerify(); |
| +#endif |
| + |
| + private: |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| +}; |
| + |
| + |
| // The ExternalString class describes string values that are backed by |
| // a string resource that lies outside the V8 heap. ExternalStrings |
| // consist of the length field common to all strings, a pointer to the |