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 7487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7498 if (*chars > kMaxAsciiCharCodeU) return static_cast<int>(chars - start); | 7498 if (*chars > kMaxAsciiCharCodeU) return static_cast<int>(chars - start); |
7499 ++chars; | 7499 ++chars; |
7500 } | 7500 } |
7501 return static_cast<int>(chars - start); | 7501 return static_cast<int>(chars - start); |
7502 } | 7502 } |
7503 | 7503 |
7504 static inline bool IsAscii(const uc16* chars, int length) { | 7504 static inline bool IsAscii(const uc16* chars, int length) { |
7505 return NonAsciiStart(chars, length) >= length; | 7505 return NonAsciiStart(chars, length) >= length; |
7506 } | 7506 } |
7507 | 7507 |
| 7508 template<class Visitor, class ConsOp> |
| 7509 static inline void Visit(String* string, |
| 7510 unsigned offset, |
| 7511 Visitor& visitor, |
| 7512 ConsOp& consOp, |
| 7513 int32_t type, |
| 7514 unsigned length); |
| 7515 |
7508 protected: | 7516 protected: |
7509 class ReadBlockBuffer { | 7517 class ReadBlockBuffer { |
7510 public: | 7518 public: |
7511 ReadBlockBuffer(unibrow::byte* util_buffer_, | 7519 ReadBlockBuffer(unibrow::byte* util_buffer_, |
7512 unsigned cursor_, | 7520 unsigned cursor_, |
7513 unsigned capacity_, | 7521 unsigned capacity_, |
7514 unsigned remaining_) : | 7522 unsigned remaining_) : |
7515 util_buffer(util_buffer_), | 7523 util_buffer(util_buffer_), |
7516 cursor(cursor_), | 7524 cursor(cursor_), |
7517 capacity(capacity_), | 7525 capacity(capacity_), |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7947 // not always desirable, however (esp. in debugging situations). | 7955 // not always desirable, however (esp. in debugging situations). |
7948 class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { | 7956 class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
7949 public: | 7957 public: |
7950 virtual void Seek(unsigned pos); | 7958 virtual void Seek(unsigned pos); |
7951 inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} | 7959 inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
7952 explicit inline StringInputBuffer(String* backing): | 7960 explicit inline StringInputBuffer(String* backing): |
7953 unibrow::InputBuffer<String, String*, 1024>(backing) {} | 7961 unibrow::InputBuffer<String, String*, 1024>(backing) {} |
7954 }; | 7962 }; |
7955 | 7963 |
7956 | 7964 |
| 7965 // This maintains an off-stack representation of the stack frames required |
| 7966 // to traverse a ConsString, allowing an entirely iterative and restartable |
| 7967 // traversal of the entire string |
| 7968 // Note: this class is not GC-safe. |
| 7969 class ConsStringIteratorOp { |
| 7970 public: |
| 7971 struct ContinueResponse { |
| 7972 String* string_; |
| 7973 unsigned offset_; |
| 7974 unsigned length_; |
| 7975 int32_t type_; |
| 7976 }; |
| 7977 inline ConsStringIteratorOp() {} |
| 7978 String* Operate(ConsString* consString, unsigned* outerOffset, |
| 7979 int32_t* typeOut, unsigned* lengthOut); |
| 7980 inline bool ContinueOperation(ContinueResponse* response); |
| 7981 inline void Reset(); |
| 7982 inline bool HasMore(); |
| 7983 |
| 7984 private: |
| 7985 // TODO(dcarney): Templatize this out for different stack sizes. |
| 7986 static const unsigned kStackSize = 32; |
| 7987 // Use a mask instead of doing modulo operations for stack wrapping. |
| 7988 static const unsigned kDepthMask = kStackSize-1; |
| 7989 STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize)); |
| 7990 static inline unsigned OffsetForDepth(unsigned depth); |
| 7991 static inline uint32_t MaskForDepth(unsigned depth); |
| 7992 |
| 7993 inline void ClearRightDescent(); |
| 7994 inline void SetRightDescent(); |
| 7995 inline void PushLeft(ConsString* string); |
| 7996 inline void PushRight(ConsString* string, int32_t type); |
| 7997 inline void AdjustMaximumDepth(); |
| 7998 inline void Pop(); |
| 7999 inline void ResetStack(); |
| 8000 String* NextLeaf(bool* blewStack, int32_t* typeOut); |
| 8001 |
| 8002 unsigned depth_; |
| 8003 unsigned maximum_depth_; |
| 8004 uint32_t trace_; |
| 8005 ConsString* frames_[kStackSize]; |
| 8006 unsigned consumed_; |
| 8007 ConsString* root_; |
| 8008 int32_t root_type_; |
| 8009 unsigned root_length_; |
| 8010 DISALLOW_COPY_AND_ASSIGN(ConsStringIteratorOp); |
| 8011 }; |
| 8012 |
| 8013 |
| 8014 // Note: this class is not GC-safe. |
| 8015 class StringCharacterStream { |
| 8016 public: |
| 8017 inline StringCharacterStream( |
| 8018 String* string, unsigned offset, ConsStringIteratorOp* op); |
| 8019 inline uint16_t GetNext(); |
| 8020 inline bool HasMore(); |
| 8021 inline void Reset(String* string, unsigned offset, ConsStringIteratorOp* op); |
| 8022 inline void VisitOneByteString(const uint8_t* chars, unsigned length); |
| 8023 inline void VisitTwoByteString(const uint16_t* chars, unsigned length); |
| 8024 |
| 8025 private: |
| 8026 bool is_one_byte_; |
| 8027 union { |
| 8028 const uint8_t* buffer8_; |
| 8029 const uint16_t* buffer16_; |
| 8030 }; |
| 8031 const uint8_t* end_; |
| 8032 ConsStringIteratorOp* op_; |
| 8033 DISALLOW_COPY_AND_ASSIGN(StringCharacterStream); |
| 8034 }; |
| 8035 |
| 8036 |
7957 template <typename T> | 8037 template <typename T> |
7958 class VectorIterator { | 8038 class VectorIterator { |
7959 public: | 8039 public: |
7960 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } | 8040 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
7961 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } | 8041 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
7962 T GetNext() { return data_[index_++]; } | 8042 T GetNext() { return data_[index_++]; } |
7963 bool has_more() { return index_ < data_.length(); } | 8043 bool has_more() { return index_ < data_.length(); } |
7964 private: | 8044 private: |
7965 Vector<const T> data_; | 8045 Vector<const T> data_; |
7966 int index_; | 8046 int index_; |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8996 } else { | 9076 } else { |
8997 value &= ~(1 << bit_position); | 9077 value &= ~(1 << bit_position); |
8998 } | 9078 } |
8999 return value; | 9079 return value; |
9000 } | 9080 } |
9001 }; | 9081 }; |
9002 | 9082 |
9003 } } // namespace v8::internal | 9083 } } // namespace v8::internal |
9004 | 9084 |
9005 #endif // V8_OBJECTS_H_ | 9085 #endif // V8_OBJECTS_H_ |
OLD | NEW |