OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/assert-scope.h" | 10 #include "src/assert-scope.h" |
(...skipping 8627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8638 }; | 8638 }; |
8639 | 8639 |
8640 // Representation of the flat content of a String. | 8640 // Representation of the flat content of a String. |
8641 // A non-flat string doesn't have flat content. | 8641 // A non-flat string doesn't have flat content. |
8642 // A flat string has content that's encoded as a sequence of either | 8642 // A flat string has content that's encoded as a sequence of either |
8643 // one-byte chars or two-byte UC16. | 8643 // one-byte chars or two-byte UC16. |
8644 // Returned by String::GetFlatContent(). | 8644 // Returned by String::GetFlatContent(). |
8645 class FlatContent { | 8645 class FlatContent { |
8646 public: | 8646 public: |
8647 // Returns true if the string is flat and this structure contains content. | 8647 // Returns true if the string is flat and this structure contains content. |
8648 bool IsFlat() { return state_ != NON_FLAT; } | 8648 bool IsFlat() const { return state_ != NON_FLAT; } |
8649 // Returns true if the structure contains one-byte content. | 8649 // Returns true if the structure contains one-byte content. |
8650 bool IsOneByte() { return state_ == ONE_BYTE; } | 8650 bool IsOneByte() const { return state_ == ONE_BYTE; } |
8651 // Returns true if the structure contains two-byte content. | 8651 // Returns true if the structure contains two-byte content. |
8652 bool IsTwoByte() { return state_ == TWO_BYTE; } | 8652 bool IsTwoByte() const { return state_ == TWO_BYTE; } |
8653 | 8653 |
8654 // Return the one byte content of the string. Only use if IsOneByte() | 8654 // Return the one byte content of the string. Only use if IsOneByte() |
8655 // returns true. | 8655 // returns true. |
8656 Vector<const uint8_t> ToOneByteVector() { | 8656 Vector<const uint8_t> ToOneByteVector() const { |
8657 DCHECK_EQ(ONE_BYTE, state_); | 8657 DCHECK_EQ(ONE_BYTE, state_); |
8658 return Vector<const uint8_t>(onebyte_start, length_); | 8658 return Vector<const uint8_t>(onebyte_start, length_); |
8659 } | 8659 } |
8660 // Return the two-byte content of the string. Only use if IsTwoByte() | 8660 // Return the two-byte content of the string. Only use if IsTwoByte() |
8661 // returns true. | 8661 // returns true. |
8662 Vector<const uc16> ToUC16Vector() { | 8662 Vector<const uc16> ToUC16Vector() const { |
8663 DCHECK_EQ(TWO_BYTE, state_); | 8663 DCHECK_EQ(TWO_BYTE, state_); |
8664 return Vector<const uc16>(twobyte_start, length_); | 8664 return Vector<const uc16>(twobyte_start, length_); |
8665 } | 8665 } |
8666 | 8666 |
8667 uc16 Get(int i) { | 8667 uc16 Get(int i) const { |
8668 DCHECK(i < length_); | 8668 DCHECK(i < length_); |
8669 DCHECK(state_ != NON_FLAT); | 8669 DCHECK(state_ != NON_FLAT); |
8670 if (state_ == ONE_BYTE) return onebyte_start[i]; | 8670 if (state_ == ONE_BYTE) return onebyte_start[i]; |
8671 return twobyte_start[i]; | 8671 return twobyte_start[i]; |
8672 } | 8672 } |
8673 | 8673 |
8674 bool UsesSameString(const FlatContent& other) const { | 8674 bool UsesSameString(const FlatContent& other) const { |
8675 return onebyte_start == other.onebyte_start; | 8675 return onebyte_start == other.onebyte_start; |
8676 } | 8676 } |
8677 | 8677 |
(...skipping 2055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10733 } | 10733 } |
10734 return value; | 10734 return value; |
10735 } | 10735 } |
10736 }; | 10736 }; |
10737 | 10737 |
10738 | 10738 |
10739 } // NOLINT, false-positive due to second-order macros. | 10739 } // NOLINT, false-positive due to second-order macros. |
10740 } // NOLINT, false-positive due to second-order macros. | 10740 } // NOLINT, false-positive due to second-order macros. |
10741 | 10741 |
10742 #endif // V8_OBJECTS_H_ | 10742 #endif // V8_OBJECTS_H_ |
OLD | NEW |