OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include "allocation.h" | 8 #include "allocation.h" |
9 #include "assert-scope.h" | 9 #include "assert-scope.h" |
10 #include "builtins.h" | 10 #include "builtins.h" |
(...skipping 9191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9202 if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start); | 9202 if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start); |
9203 ++chars; | 9203 ++chars; |
9204 } | 9204 } |
9205 return static_cast<int>(chars - start); | 9205 return static_cast<int>(chars - start); |
9206 } | 9206 } |
9207 | 9207 |
9208 static inline bool IsOneByte(const uc16* chars, int length) { | 9208 static inline bool IsOneByte(const uc16* chars, int length) { |
9209 return NonOneByteStart(chars, length) >= length; | 9209 return NonOneByteStart(chars, length) >= length; |
9210 } | 9210 } |
9211 | 9211 |
9212 // TODO(dcarney): Replace all instances of this with VisitFlat. | |
9213 template<class Visitor, class ConsOp> | |
9214 static inline void Visit(String* string, | |
9215 unsigned offset, | |
9216 Visitor& visitor, | |
9217 ConsOp& cons_op, | |
9218 int32_t type, | |
9219 unsigned length); | |
9220 | |
9221 template<class Visitor> | 9212 template<class Visitor> |
9222 static inline ConsString* VisitFlat(Visitor* visitor, | 9213 static inline ConsString* VisitFlat(Visitor* visitor, |
9223 String* string, | 9214 String* string, |
9224 int offset, | 9215 int offset = 0); |
9225 int length, | |
9226 int32_t type); | |
9227 | |
9228 template<class Visitor> | |
9229 static inline ConsString* VisitFlat(Visitor* visitor, | |
9230 String* string, | |
9231 int offset = 0) { | |
9232 int32_t type = string->map()->instance_type(); | |
9233 return VisitFlat(visitor, string, offset, string->length(), type); | |
9234 } | |
9235 | 9216 |
9236 static Handle<FixedArray> CalculateLineEnds(Handle<String> string, | 9217 static Handle<FixedArray> CalculateLineEnds(Handle<String> string, |
9237 bool include_ending_line); | 9218 bool include_ending_line); |
9238 | 9219 |
9239 private: | 9220 private: |
9240 friend class Name; | 9221 friend class Name; |
9241 | 9222 |
9242 static Handle<String> SlowFlatten(Handle<ConsString> cons, | 9223 static Handle<String> SlowFlatten(Handle<ConsString> cons, |
9243 PretenureFlag tenure); | 9224 PretenureFlag tenure); |
9244 | 9225 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9610 inline ConsStringNullOp() {} | 9591 inline ConsStringNullOp() {} |
9611 static inline String* Operate(String*, unsigned*, int32_t*, unsigned*); | 9592 static inline String* Operate(String*, unsigned*, int32_t*, unsigned*); |
9612 private: | 9593 private: |
9613 DISALLOW_COPY_AND_ASSIGN(ConsStringNullOp); | 9594 DISALLOW_COPY_AND_ASSIGN(ConsStringNullOp); |
9614 }; | 9595 }; |
9615 | 9596 |
9616 | 9597 |
9617 // This maintains an off-stack representation of the stack frames required | 9598 // This maintains an off-stack representation of the stack frames required |
9618 // to traverse a ConsString, allowing an entirely iterative and restartable | 9599 // to traverse a ConsString, allowing an entirely iterative and restartable |
9619 // traversal of the entire string | 9600 // traversal of the entire string |
9620 // Note: this class is not GC-safe. | |
9621 class ConsStringIteratorOp { | 9601 class ConsStringIteratorOp { |
9622 public: | 9602 public: |
9623 inline ConsStringIteratorOp() {} | 9603 inline ConsStringIteratorOp() {} |
9624 String* Operate(String* string, | 9604 inline ConsStringIteratorOp(ConsString* cons_string, int offset = 0) { |
9625 unsigned* offset_out, | 9605 Reset(cons_string, offset); |
9626 int32_t* type_out, | 9606 } |
9627 unsigned* length_out); | 9607 inline void Reset(ConsString* cons_string, int offset = 0) { |
9628 inline String* ContinueOperation(int32_t* type_out, unsigned* length_out); | 9608 depth_ = 0; |
9629 inline void Reset(); | 9609 // Next will always return NULL. |
9630 inline bool HasMore(); | 9610 if (cons_string == NULL) return; |
| 9611 Initialize(cons_string, offset); |
| 9612 } |
| 9613 // Returns NULL when complete. |
| 9614 inline String* Next(int* offset_out) { |
| 9615 *offset_out = 0; |
| 9616 if (depth_ == 0) return NULL; |
| 9617 return Continue(offset_out); |
| 9618 } |
9631 | 9619 |
9632 private: | 9620 private: |
9633 // TODO(dcarney): Templatize this out for different stack sizes. | 9621 static const int kStackSize = 32; |
9634 static const unsigned kStackSize = 32; | |
9635 // Use a mask instead of doing modulo operations for stack wrapping. | 9622 // Use a mask instead of doing modulo operations for stack wrapping. |
9636 static const unsigned kDepthMask = kStackSize-1; | 9623 static const int kDepthMask = kStackSize-1; |
9637 STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize)); | 9624 STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize)); |
9638 static inline unsigned OffsetForDepth(unsigned depth); | 9625 static inline int OffsetForDepth(int depth); |
9639 | 9626 |
9640 inline void PushLeft(ConsString* string); | 9627 inline void PushLeft(ConsString* string); |
9641 inline void PushRight(ConsString* string); | 9628 inline void PushRight(ConsString* string); |
9642 inline void AdjustMaximumDepth(); | 9629 inline void AdjustMaximumDepth(); |
9643 inline void Pop(); | 9630 inline void Pop(); |
9644 String* NextLeaf(bool* blew_stack, int32_t* type_out, unsigned* length_out); | 9631 inline bool StackBlown() { return maximum_depth_ - depth_ == kStackSize; } |
9645 String* Search(unsigned* offset_out, | 9632 void Initialize(ConsString* cons_string, int offset); |
9646 int32_t* type_out, | 9633 String* Continue(int* offset_out); |
9647 unsigned* length_out); | 9634 String* NextLeaf(bool* blew_stack); |
| 9635 String* Search(int* offset_out); |
9648 | 9636 |
9649 unsigned depth_; | |
9650 unsigned maximum_depth_; | |
9651 // Stack must always contain only frames for which right traversal | 9637 // Stack must always contain only frames for which right traversal |
9652 // has not yet been performed. | 9638 // has not yet been performed. |
9653 ConsString* frames_[kStackSize]; | 9639 ConsString* frames_[kStackSize]; |
9654 unsigned consumed_; | |
9655 ConsString* root_; | 9640 ConsString* root_; |
| 9641 int depth_; |
| 9642 int maximum_depth_; |
| 9643 int consumed_; |
9656 DISALLOW_COPY_AND_ASSIGN(ConsStringIteratorOp); | 9644 DISALLOW_COPY_AND_ASSIGN(ConsStringIteratorOp); |
9657 }; | 9645 }; |
9658 | 9646 |
9659 | 9647 |
9660 // Note: this class is not GC-safe. | |
9661 class StringCharacterStream { | 9648 class StringCharacterStream { |
9662 public: | 9649 public: |
9663 inline StringCharacterStream(String* string, | 9650 inline StringCharacterStream(String* string, |
9664 ConsStringIteratorOp* op, | 9651 ConsStringIteratorOp* op, |
9665 unsigned offset = 0); | 9652 int offset = 0); |
9666 inline uint16_t GetNext(); | 9653 inline uint16_t GetNext(); |
9667 inline bool HasMore(); | 9654 inline bool HasMore(); |
9668 inline void Reset(String* string, unsigned offset = 0); | 9655 inline void Reset(String* string, int offset = 0); |
9669 inline void VisitOneByteString(const uint8_t* chars, unsigned length); | 9656 inline void VisitOneByteString(const uint8_t* chars, int length); |
9670 inline void VisitTwoByteString(const uint16_t* chars, unsigned length); | 9657 inline void VisitTwoByteString(const uint16_t* chars, int length); |
9671 | 9658 |
9672 private: | 9659 private: |
9673 bool is_one_byte_; | 9660 bool is_one_byte_; |
9674 union { | 9661 union { |
9675 const uint8_t* buffer8_; | 9662 const uint8_t* buffer8_; |
9676 const uint16_t* buffer16_; | 9663 const uint16_t* buffer16_; |
9677 }; | 9664 }; |
9678 const uint8_t* end_; | 9665 const uint8_t* end_; |
9679 ConsStringIteratorOp* op_; | 9666 ConsStringIteratorOp* op_; |
9680 DISALLOW_COPY_AND_ASSIGN(StringCharacterStream); | 9667 DISALLOW_COPY_AND_ASSIGN(StringCharacterStream); |
(...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11194 } else { | 11181 } else { |
11195 value &= ~(1 << bit_position); | 11182 value &= ~(1 << bit_position); |
11196 } | 11183 } |
11197 return value; | 11184 return value; |
11198 } | 11185 } |
11199 }; | 11186 }; |
11200 | 11187 |
11201 } } // namespace v8::internal | 11188 } } // namespace v8::internal |
11202 | 11189 |
11203 #endif // V8_OBJECTS_H_ | 11190 #endif // V8_OBJECTS_H_ |
OLD | NEW |