OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 7488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7499 if (*chars > kMaxAsciiCharCodeU) return static_cast<int>(chars - start); | 7499 if (*chars > kMaxAsciiCharCodeU) return static_cast<int>(chars - start); |
7500 ++chars; | 7500 ++chars; |
7501 } | 7501 } |
7502 return static_cast<int>(chars - start); | 7502 return static_cast<int>(chars - start); |
7503 } | 7503 } |
7504 | 7504 |
7505 static inline bool IsAscii(const uc16* chars, int length) { | 7505 static inline bool IsAscii(const uc16* chars, int length) { |
7506 return NonAsciiStart(chars, length) >= length; | 7506 return NonAsciiStart(chars, length) >= length; |
7507 } | 7507 } |
7508 | 7508 |
7509 template<class Visitor, class ConsOp> | |
7510 static inline void Visit(String* string, | |
Yang
2012/12/04 14:49:11
Why is this part of the String class and not part
| |
7511 unsigned offset, | |
7512 Visitor& visitor, | |
7513 ConsOp& consOp, | |
7514 int32_t type, | |
7515 unsigned length); | |
7516 | |
7509 protected: | 7517 protected: |
7510 class ReadBlockBuffer { | 7518 class ReadBlockBuffer { |
7511 public: | 7519 public: |
7512 ReadBlockBuffer(unibrow::byte* util_buffer_, | 7520 ReadBlockBuffer(unibrow::byte* util_buffer_, |
7513 unsigned cursor_, | 7521 unsigned cursor_, |
7514 unsigned capacity_, | 7522 unsigned capacity_, |
7515 unsigned remaining_) : | 7523 unsigned remaining_) : |
7516 util_buffer(util_buffer_), | 7524 util_buffer(util_buffer_), |
7517 cursor(cursor_), | 7525 cursor(cursor_), |
7518 capacity(capacity_), | 7526 capacity(capacity_), |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7959 : public unibrow::InputBuffer<String, String**, 256> { | 7967 : public unibrow::InputBuffer<String, String**, 256> { |
7960 public: | 7968 public: |
7961 virtual void Seek(unsigned pos); | 7969 virtual void Seek(unsigned pos); |
7962 inline SafeStringInputBuffer() | 7970 inline SafeStringInputBuffer() |
7963 : unibrow::InputBuffer<String, String**, 256>() {} | 7971 : unibrow::InputBuffer<String, String**, 256>() {} |
7964 explicit inline SafeStringInputBuffer(String** backing) | 7972 explicit inline SafeStringInputBuffer(String** backing) |
7965 : unibrow::InputBuffer<String, String**, 256>(backing) {} | 7973 : unibrow::InputBuffer<String, String**, 256>(backing) {} |
7966 }; | 7974 }; |
7967 | 7975 |
7968 | 7976 |
7977 // This maintains an off-stack representation of the stack frames required | |
7978 // to traverse a ConsString, allowing an entirely iterative and restartable | |
7979 // traversal of the entire string | |
7980 class ConsStringIteratorOp { | |
7981 public: | |
7982 struct ContinueResponse { | |
7983 String* string; | |
7984 unsigned offset; | |
7985 unsigned length; | |
7986 int32_t type; | |
7987 }; | |
7988 inline ConsStringIteratorOp() {} | |
7989 String* Operate(ConsString* consString, unsigned* outerOffset, | |
7990 int32_t* typeOut, unsigned* lengthOut); | |
7991 inline bool ContinueOperation(ContinueResponse* response); | |
7992 inline void Reset(); | |
7993 inline bool HasMore(); | |
7994 | |
7995 private: | |
7996 // TODO(dcarney): Templatize this out for different stack sizes. | |
7997 static const unsigned stackSize = 32; | |
Yang
2012/12/04 14:49:11
Please write constants in camel case starting with
| |
7998 // Use a mask instead of doing modulo operations for stack wrapping. | |
7999 static const unsigned depthMask = 0x1F; | |
Yang
2012/12/04 14:49:11
Could you write that as stackSize - 1 and assert t
| |
8000 static inline unsigned OffsetForDepth(unsigned depth); | |
8001 static inline uint32_t MaskForDepth(unsigned depth); | |
8002 | |
8003 inline void ClearRightDescent(); | |
8004 inline void SetRightDescent(); | |
8005 inline void PushLeft(ConsString* string); | |
8006 inline void PushRight(ConsString* string, int32_t type); | |
8007 inline void AdjustMaximumDepth(); | |
8008 inline void Pop(); | |
8009 inline void ResetStack(); | |
8010 String* NextLeaf(bool* blewStack, int32_t* typeOut); | |
8011 | |
8012 unsigned depth; | |
Yang
2012/12/04 14:49:11
Please add an underscore to all member variables,
| |
8013 unsigned maximumDepth; | |
8014 uint32_t trace; | |
8015 ConsString* frames[stackSize]; | |
Yang
2012/12/04 14:49:11
I wonder if you could just use a ZoneList to alloc
| |
8016 unsigned consumed; | |
8017 ConsString* root; | |
8018 int32_t rootType; | |
8019 unsigned rootLength; | |
8020 DISALLOW_COPY_AND_ASSIGN(ConsStringIteratorOp); | |
8021 }; | |
8022 | |
8023 | |
8024 class StringBufferStream { | |
Yang
2012/12/04 14:49:11
Different than what the name suggests, this class
| |
8025 public: | |
8026 // All initialization done in Reset. | |
8027 inline StringBufferStream() {} | |
Yang
2012/12/04 14:49:11
I think it would be less error prone if the constr
| |
8028 inline uint16_t GetNext(); | |
8029 inline bool has_more(); | |
8030 inline void Reset(String* string, unsigned offset, ConsStringIteratorOp* op); | |
8031 inline void VisitOneByteString(const uint8_t* chars, unsigned length); | |
8032 inline void VisitTwoByteString(const uint16_t* chars, unsigned length); | |
8033 | |
8034 private: | |
8035 bool isOneByte; | |
8036 union { | |
8037 const uint8_t* buffer8; | |
8038 const uint16_t* buffer16; | |
Yang
2012/12/04 14:49:11
Instead of using a pointer into the string, using
| |
8039 }; | |
8040 const uint8_t* end; | |
8041 ConsStringIteratorOp* op; | |
8042 DISALLOW_COPY_AND_ASSIGN(StringBufferStream); | |
8043 }; | |
8044 | |
8045 | |
7969 template <typename T> | 8046 template <typename T> |
7970 class VectorIterator { | 8047 class VectorIterator { |
7971 public: | 8048 public: |
7972 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } | 8049 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
7973 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } | 8050 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
7974 T GetNext() { return data_[index_++]; } | 8051 T GetNext() { return data_[index_++]; } |
7975 bool has_more() { return index_ < data_.length(); } | 8052 bool has_more() { return index_ < data_.length(); } |
7976 private: | 8053 private: |
7977 Vector<const T> data_; | 8054 Vector<const T> data_; |
7978 int index_; | 8055 int index_; |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9008 } else { | 9085 } else { |
9009 value &= ~(1 << bit_position); | 9086 value &= ~(1 << bit_position); |
9010 } | 9087 } |
9011 return value; | 9088 return value; |
9012 } | 9089 } |
9013 }; | 9090 }; |
9014 | 9091 |
9015 } } // namespace v8::internal | 9092 } } // namespace v8::internal |
9016 | 9093 |
9017 #endif // V8_OBJECTS_H_ | 9094 #endif // V8_OBJECTS_H_ |
OLD | NEW |