Index: src/objects.h |
diff --git a/src/objects.h b/src/objects.h |
index c476692d7638d288590bed935622d19e90828eb9..f61621baf99a131b8f63ca54a7cee16f4e71b775 100644 |
--- a/src/objects.h |
+++ b/src/objects.h |
@@ -7506,6 +7506,14 @@ class String: public HeapObject { |
return NonAsciiStart(chars, length) >= length; |
} |
+ template<class Visitor, class ConsOp> |
+ static inline void Visit(String* string, |
Yang
2012/12/04 14:49:11
Why is this part of the String class and not part
|
+ unsigned offset, |
+ Visitor& visitor, |
+ ConsOp& consOp, |
+ int32_t type, |
+ unsigned length); |
+ |
protected: |
class ReadBlockBuffer { |
public: |
@@ -7966,6 +7974,75 @@ class SafeStringInputBuffer |
}; |
+// This maintains an off-stack representation of the stack frames required |
+// to traverse a ConsString, allowing an entirely iterative and restartable |
+// traversal of the entire string |
+class ConsStringIteratorOp { |
+ public: |
+ struct ContinueResponse { |
+ String* string; |
+ unsigned offset; |
+ unsigned length; |
+ int32_t type; |
+ }; |
+ inline ConsStringIteratorOp() {} |
+ String* Operate(ConsString* consString, unsigned* outerOffset, |
+ int32_t* typeOut, unsigned* lengthOut); |
+ inline bool ContinueOperation(ContinueResponse* response); |
+ inline void Reset(); |
+ inline bool HasMore(); |
+ |
+ private: |
+ // TODO(dcarney): Templatize this out for different stack sizes. |
+ static const unsigned stackSize = 32; |
Yang
2012/12/04 14:49:11
Please write constants in camel case starting with
|
+ // Use a mask instead of doing modulo operations for stack wrapping. |
+ static const unsigned depthMask = 0x1F; |
Yang
2012/12/04 14:49:11
Could you write that as stackSize - 1 and assert t
|
+ static inline unsigned OffsetForDepth(unsigned depth); |
+ static inline uint32_t MaskForDepth(unsigned depth); |
+ |
+ inline void ClearRightDescent(); |
+ inline void SetRightDescent(); |
+ inline void PushLeft(ConsString* string); |
+ inline void PushRight(ConsString* string, int32_t type); |
+ inline void AdjustMaximumDepth(); |
+ inline void Pop(); |
+ inline void ResetStack(); |
+ String* NextLeaf(bool* blewStack, int32_t* typeOut); |
+ |
+ unsigned depth; |
Yang
2012/12/04 14:49:11
Please add an underscore to all member variables,
|
+ unsigned maximumDepth; |
+ uint32_t trace; |
+ ConsString* frames[stackSize]; |
Yang
2012/12/04 14:49:11
I wonder if you could just use a ZoneList to alloc
|
+ unsigned consumed; |
+ ConsString* root; |
+ int32_t rootType; |
+ unsigned rootLength; |
+ DISALLOW_COPY_AND_ASSIGN(ConsStringIteratorOp); |
+}; |
+ |
+ |
+class StringBufferStream { |
Yang
2012/12/04 14:49:11
Different than what the name suggests, this class
|
+ public: |
+ // All initialization done in Reset. |
+ inline StringBufferStream() {} |
Yang
2012/12/04 14:49:11
I think it would be less error prone if the constr
|
+ inline uint16_t GetNext(); |
+ inline bool has_more(); |
+ inline void Reset(String* string, unsigned offset, ConsStringIteratorOp* op); |
+ inline void VisitOneByteString(const uint8_t* chars, unsigned length); |
+ inline void VisitTwoByteString(const uint16_t* chars, unsigned length); |
+ |
+ private: |
+ bool isOneByte; |
+ union { |
+ const uint8_t* buffer8; |
+ const uint16_t* buffer16; |
Yang
2012/12/04 14:49:11
Instead of using a pointer into the string, using
|
+ }; |
+ const uint8_t* end; |
+ ConsStringIteratorOp* op; |
+ DISALLOW_COPY_AND_ASSIGN(StringBufferStream); |
+}; |
+ |
+ |
template <typename T> |
class VectorIterator { |
public: |