| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_VECTOR_H_ | 5 #ifndef V8_VECTOR_H_ |
| 6 #define V8_VECTOR_H_ | 6 #define V8_VECTOR_H_ |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 // Releases the array underlying this vector. Once disposed the | 85 // Releases the array underlying this vector. Once disposed the |
| 86 // vector is empty. | 86 // vector is empty. |
| 87 void Dispose() { | 87 void Dispose() { |
| 88 DeleteArray(start_); | 88 DeleteArray(start_); |
| 89 start_ = NULL; | 89 start_ = NULL; |
| 90 length_ = 0; | 90 length_ = 0; |
| 91 } | 91 } |
| 92 | 92 |
| 93 inline Vector<T> operator+(int offset) { | 93 inline Vector<T> operator+(int offset) { |
| 94 DCHECK(offset < length_); | 94 DCHECK(offset <= length_); |
| 95 return Vector<T>(start_ + offset, length_ - offset); | 95 return Vector<T>(start_ + offset, length_ - offset); |
| 96 } | 96 } |
| 97 | 97 |
| 98 inline Vector<T>& operator+=(int offset) { |
| 99 DCHECK(offset <= length_); |
| 100 start_ += offset; |
| 101 length_ -= offset; |
| 102 return *this; |
| 103 } |
| 104 |
| 98 // Factory method for creating empty vectors. | 105 // Factory method for creating empty vectors. |
| 99 static Vector<T> empty() { return Vector<T>(NULL, 0); } | 106 static Vector<T> empty() { return Vector<T>(NULL, 0); } |
| 100 | 107 |
| 101 template<typename S> | 108 template<typename S> |
| 102 static Vector<T> cast(Vector<S> input) { | 109 static Vector<T> cast(Vector<S> input) { |
| 103 return Vector<T>(reinterpret_cast<T*>(input.start()), | 110 return Vector<T>(reinterpret_cast<T*>(input.start()), |
| 104 input.length() * sizeof(S) / sizeof(T)); | 111 input.length() * sizeof(S) / sizeof(T)); |
| 105 } | 112 } |
| 106 | 113 |
| 107 bool operator==(const Vector<T>& other) const { | 114 bool operator==(const Vector<T>& other) const { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 184 |
| 178 inline Vector<char> MutableCStrVector(char* data, int max) { | 185 inline Vector<char> MutableCStrVector(char* data, int max) { |
| 179 int length = StrLength(data); | 186 int length = StrLength(data); |
| 180 return Vector<char>(data, (length < max) ? length : max); | 187 return Vector<char>(data, (length < max) ? length : max); |
| 181 } | 188 } |
| 182 | 189 |
| 183 | 190 |
| 184 } } // namespace v8::internal | 191 } } // namespace v8::internal |
| 185 | 192 |
| 186 #endif // V8_VECTOR_H_ | 193 #endif // V8_VECTOR_H_ |
| OLD | NEW |