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 13 matching lines...) Expand all Loading... |
24 DCHECK(length == 0 || (length > 0 && data != NULL)); | 24 DCHECK(length == 0 || (length > 0 && data != NULL)); |
25 } | 25 } |
26 | 26 |
27 static Vector<T> New(int length) { | 27 static Vector<T> New(int length) { |
28 return Vector<T>(NewArray<T>(length), length); | 28 return Vector<T>(NewArray<T>(length), length); |
29 } | 29 } |
30 | 30 |
31 // Returns a vector using the same backing storage as this one, | 31 // Returns a vector using the same backing storage as this one, |
32 // spanning from and including 'from', to but not including 'to'. | 32 // spanning from and including 'from', to but not including 'to'. |
33 Vector<T> SubVector(int from, int to) { | 33 Vector<T> SubVector(int from, int to) { |
34 SLOW_DCHECK(to <= length_); | 34 DCHECK(0 <= from); |
35 SLOW_DCHECK(from < to); | 35 SLOW_DCHECK(from < to); |
36 DCHECK(0 <= from); | 36 SLOW_DCHECK(static_cast<unsigned>(to) <= static_cast<unsigned>(length_)); |
37 return Vector<T>(start() + from, to - from); | 37 return Vector<T>(start() + from, to - from); |
38 } | 38 } |
39 | 39 |
40 // Returns the length of the vector. | 40 // Returns the length of the vector. |
41 int length() const { return length_; } | 41 int length() const { return length_; } |
42 | 42 |
43 // Returns whether or not the vector is empty. | 43 // Returns whether or not the vector is empty. |
44 bool is_empty() const { return length_ == 0; } | 44 bool is_empty() const { return length_ == 0; } |
45 | 45 |
46 // Returns the pointer to the start of the data in the vector. | 46 // Returns the pointer to the start of the data in the vector. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 inline Vector<char> MutableCStrVector(char* data, int max) { | 178 inline Vector<char> MutableCStrVector(char* data, int max) { |
179 int length = StrLength(data); | 179 int length = StrLength(data); |
180 return Vector<char>(data, (length < max) ? length : max); | 180 return Vector<char>(data, (length < max) ? length : max); |
181 } | 181 } |
182 | 182 |
183 | 183 |
184 } } // namespace v8::internal | 184 } } // namespace v8::internal |
185 | 185 |
186 #endif // V8_VECTOR_H_ | 186 #endif // V8_VECTOR_H_ |
OLD | NEW |