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 8685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8696 }; | 8696 }; |
8697 | 8697 |
8698 // Representation of the flat content of a String. | 8698 // Representation of the flat content of a String. |
8699 // A non-flat string doesn't have flat content. | 8699 // A non-flat string doesn't have flat content. |
8700 // A flat string has content that's encoded as a sequence of either | 8700 // A flat string has content that's encoded as a sequence of either |
8701 // one-byte chars or two-byte UC16. | 8701 // one-byte chars or two-byte UC16. |
8702 // Returned by String::GetFlatContent(). | 8702 // Returned by String::GetFlatContent(). |
8703 class FlatContent { | 8703 class FlatContent { |
8704 public: | 8704 public: |
8705 // Returns true if the string is flat and this structure contains content. | 8705 // Returns true if the string is flat and this structure contains content. |
8706 bool IsFlat() { return state_ != NON_FLAT; } | 8706 bool IsFlat() const { return state_ != NON_FLAT; } |
8707 // Returns true if the structure contains one-byte content. | 8707 // Returns true if the structure contains one-byte content. |
8708 bool IsOneByte() { return state_ == ONE_BYTE; } | 8708 bool IsOneByte() const { return state_ == ONE_BYTE; } |
8709 // Returns true if the structure contains two-byte content. | 8709 // Returns true if the structure contains two-byte content. |
8710 bool IsTwoByte() { return state_ == TWO_BYTE; } | 8710 bool IsTwoByte() const { return state_ == TWO_BYTE; } |
8711 | 8711 |
8712 // Return the one byte content of the string. Only use if IsOneByte() | 8712 // Return the one byte content of the string. Only use if IsOneByte() |
8713 // returns true. | 8713 // returns true. |
8714 Vector<const uint8_t> ToOneByteVector() { | 8714 Vector<const uint8_t> ToOneByteVector() const { |
8715 DCHECK_EQ(ONE_BYTE, state_); | 8715 DCHECK_EQ(ONE_BYTE, state_); |
8716 return Vector<const uint8_t>(onebyte_start, length_); | 8716 return Vector<const uint8_t>(onebyte_start, length_); |
8717 } | 8717 } |
8718 // Return the two-byte content of the string. Only use if IsTwoByte() | 8718 // Return the two-byte content of the string. Only use if IsTwoByte() |
8719 // returns true. | 8719 // returns true. |
8720 Vector<const uc16> ToUC16Vector() { | 8720 Vector<const uc16> ToUC16Vector() const { |
8721 DCHECK_EQ(TWO_BYTE, state_); | 8721 DCHECK_EQ(TWO_BYTE, state_); |
8722 return Vector<const uc16>(twobyte_start, length_); | 8722 return Vector<const uc16>(twobyte_start, length_); |
8723 } | 8723 } |
8724 | 8724 |
8725 uc16 Get(int i) { | 8725 uc16 Get(int i) const { |
8726 DCHECK(i < length_); | 8726 DCHECK(i < length_); |
8727 DCHECK(state_ != NON_FLAT); | 8727 DCHECK(state_ != NON_FLAT); |
8728 if (state_ == ONE_BYTE) return onebyte_start[i]; | 8728 if (state_ == ONE_BYTE) return onebyte_start[i]; |
8729 return twobyte_start[i]; | 8729 return twobyte_start[i]; |
8730 } | 8730 } |
8731 | 8731 |
8732 bool UsesSameString(const FlatContent& other) const { | 8732 bool UsesSameString(const FlatContent& other) const { |
8733 return onebyte_start == other.onebyte_start; | 8733 return onebyte_start == other.onebyte_start; |
8734 } | 8734 } |
8735 | 8735 |
(...skipping 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10789 } | 10789 } |
10790 return value; | 10790 return value; |
10791 } | 10791 } |
10792 }; | 10792 }; |
10793 | 10793 |
10794 | 10794 |
10795 } // NOLINT, false-positive due to second-order macros. | 10795 } // NOLINT, false-positive due to second-order macros. |
10796 } // NOLINT, false-positive due to second-order macros. | 10796 } // NOLINT, false-positive due to second-order macros. |
10797 | 10797 |
10798 #endif // V8_OBJECTS_H_ | 10798 #endif // V8_OBJECTS_H_ |
OLD | NEW |