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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 int length() const { return length_; } | 44 int length() const { return length_; } |
45 | 45 |
46 // Returns whether or not the vector is empty. | 46 // Returns whether or not the vector is empty. |
47 bool is_empty() const { return length_ == 0; } | 47 bool is_empty() const { return length_ == 0; } |
48 | 48 |
49 // Returns the pointer to the start of the data in the vector. | 49 // Returns the pointer to the start of the data in the vector. |
50 T* start() const { return start_; } | 50 T* start() const { return start_; } |
51 | 51 |
52 // Access individual vector elements - checks bounds in debug mode. | 52 // Access individual vector elements - checks bounds in debug mode. |
53 T& operator[](int index) const { | 53 T& operator[](int index) const { |
54 DCHECK(0 <= index && index < length_); | 54 DCHECK_LE(0, index); |
| 55 DCHECK_LT(index, length_); |
55 return start_[index]; | 56 return start_[index]; |
56 } | 57 } |
57 | 58 |
58 const T& at(int index) const { return operator[](index); } | 59 const T& at(int index) const { return operator[](index); } |
59 | 60 |
60 T& first() { return start_[0]; } | 61 T& first() { return start_[0]; } |
61 | 62 |
62 T& last() { return start_[length_ - 1]; } | 63 T& last() { return start_[length_ - 1]; } |
63 | 64 |
64 typedef T* iterator; | 65 typedef T* iterator; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 207 |
207 template <typename T, int N> | 208 template <typename T, int N> |
208 inline Vector<T> ArrayVector(T (&arr)[N]) { | 209 inline Vector<T> ArrayVector(T (&arr)[N]) { |
209 return Vector<T>(arr); | 210 return Vector<T>(arr); |
210 } | 211 } |
211 | 212 |
212 } // namespace internal | 213 } // namespace internal |
213 } // namespace v8 | 214 } // namespace v8 |
214 | 215 |
215 #endif // V8_VECTOR_H_ | 216 #endif // V8_VECTOR_H_ |
OLD | NEW |