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 8622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8633 }; | 8633 }; |
8634 | 8634 |
8635 // Representation of the flat content of a String. | 8635 // Representation of the flat content of a String. |
8636 // A non-flat string doesn't have flat content. | 8636 // A non-flat string doesn't have flat content. |
8637 // A flat string has content that's encoded as a sequence of either | 8637 // A flat string has content that's encoded as a sequence of either |
8638 // one-byte chars or two-byte UC16. | 8638 // one-byte chars or two-byte UC16. |
8639 // Returned by String::GetFlatContent(). | 8639 // Returned by String::GetFlatContent(). |
8640 class FlatContent { | 8640 class FlatContent { |
8641 public: | 8641 public: |
8642 // Returns true if the string is flat and this structure contains content. | 8642 // Returns true if the string is flat and this structure contains content. |
8643 bool IsFlat() { return state_ != NON_FLAT; } | 8643 bool IsFlat() const { return state_ != NON_FLAT; } |
8644 // Returns true if the structure contains one-byte content. | 8644 // Returns true if the structure contains one-byte content. |
8645 bool IsOneByte() { return state_ == ONE_BYTE; } | 8645 bool IsOneByte() const { return state_ == ONE_BYTE; } |
8646 // Returns true if the structure contains two-byte content. | 8646 // Returns true if the structure contains two-byte content. |
8647 bool IsTwoByte() { return state_ == TWO_BYTE; } | 8647 bool IsTwoByte() const { return state_ == TWO_BYTE; } |
8648 | 8648 |
8649 // Return the one byte content of the string. Only use if IsOneByte() | 8649 // Return the one byte content of the string. Only use if IsOneByte() |
8650 // returns true. | 8650 // returns true. |
8651 Vector<const uint8_t> ToOneByteVector() { | 8651 Vector<const uint8_t> ToOneByteVector() const { |
8652 DCHECK_EQ(ONE_BYTE, state_); | 8652 DCHECK_EQ(ONE_BYTE, state_); |
8653 return Vector<const uint8_t>(onebyte_start, length_); | 8653 return Vector<const uint8_t>(onebyte_start, length_); |
8654 } | 8654 } |
8655 // Return the two-byte content of the string. Only use if IsTwoByte() | 8655 // Return the two-byte content of the string. Only use if IsTwoByte() |
8656 // returns true. | 8656 // returns true. |
8657 Vector<const uc16> ToUC16Vector() { | 8657 Vector<const uc16> ToUC16Vector() const { |
8658 DCHECK_EQ(TWO_BYTE, state_); | 8658 DCHECK_EQ(TWO_BYTE, state_); |
8659 return Vector<const uc16>(twobyte_start, length_); | 8659 return Vector<const uc16>(twobyte_start, length_); |
8660 } | 8660 } |
8661 | 8661 |
8662 uc16 Get(int i) { | 8662 uc16 Get(int i) const { |
8663 DCHECK(i < length_); | 8663 DCHECK(i < length_); |
8664 DCHECK(state_ != NON_FLAT); | 8664 DCHECK(state_ != NON_FLAT); |
8665 if (state_ == ONE_BYTE) return onebyte_start[i]; | 8665 if (state_ == ONE_BYTE) return onebyte_start[i]; |
8666 return twobyte_start[i]; | 8666 return twobyte_start[i]; |
8667 } | 8667 } |
8668 | 8668 |
8669 bool UsesSameString(const FlatContent& other) const { | 8669 bool UsesSameString(const FlatContent& other) const { |
8670 return onebyte_start == other.onebyte_start; | 8670 return onebyte_start == other.onebyte_start; |
8671 } | 8671 } |
8672 | 8672 |
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10718 } | 10718 } |
10719 return value; | 10719 return value; |
10720 } | 10720 } |
10721 }; | 10721 }; |
10722 | 10722 |
10723 | 10723 |
10724 } // NOLINT, false-positive due to second-order macros. | 10724 } // NOLINT, false-positive due to second-order macros. |
10725 } // NOLINT, false-positive due to second-order macros. | 10725 } // NOLINT, false-positive due to second-order macros. |
10726 | 10726 |
10727 #endif // V8_OBJECTS_H_ | 10727 #endif // V8_OBJECTS_H_ |
OLD | NEW |