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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 inline iterator begin() const { return &start_[0]; } | 62 inline iterator begin() const { return &start_[0]; } |
63 inline iterator end() const { return &start_[length_]; } | 63 inline iterator end() const { return &start_[length_]; } |
64 | 64 |
65 // Returns a clone of this vector with a new backing store. | 65 // Returns a clone of this vector with a new backing store. |
66 Vector<T> Clone() const { | 66 Vector<T> Clone() const { |
67 T* result = NewArray<T>(length_); | 67 T* result = NewArray<T>(length_); |
68 for (int i = 0; i < length_; i++) result[i] = start_[i]; | 68 for (int i = 0; i < length_; i++) result[i] = start_[i]; |
69 return Vector<T>(result, length_); | 69 return Vector<T>(result, length_); |
70 } | 70 } |
71 | 71 |
72 void Sort(int (*cmp)(const T*, const T*), size_t s, size_t l) { | |
73 std::sort(start() + s, start() + s + l, RawComparer(cmp)); | |
74 } | |
75 | |
76 void Sort(int (*cmp)(const T*, const T*)) { | 72 void Sort(int (*cmp)(const T*, const T*)) { |
77 std::sort(start(), start() + length(), RawComparer(cmp)); | 73 std::sort(start(), start() + length(), RawComparer(cmp)); |
78 } | 74 } |
79 | 75 |
80 void Sort() { | 76 void Sort() { |
81 std::sort(start(), start() + length()); | 77 std::sort(start(), start() + length()); |
82 } | 78 } |
83 | 79 |
84 void StableSort(int (*cmp)(const T*, const T*), size_t s, size_t l) { | |
85 std::stable_sort(start() + s, start() + s + l, RawComparer(cmp)); | |
86 } | |
87 | |
88 void StableSort(int (*cmp)(const T*, const T*)) { | |
89 std::stable_sort(start(), start() + length(), RawComparer(cmp)); | |
90 } | |
91 | |
92 void StableSort() { std::stable_sort(start(), start() + length()); } | |
93 | |
94 void Truncate(int length) { | 80 void Truncate(int length) { |
95 DCHECK(length <= length_); | 81 DCHECK(length <= length_); |
96 length_ = length; | 82 length_ = length; |
97 } | 83 } |
98 | 84 |
99 // Releases the array underlying this vector. Once disposed the | 85 // Releases the array underlying this vector. Once disposed the |
100 // vector is empty. | 86 // vector is empty. |
101 void Dispose() { | 87 void Dispose() { |
102 DeleteArray(start_); | 88 DeleteArray(start_); |
103 start_ = NULL; | 89 start_ = NULL; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 177 |
192 inline Vector<char> MutableCStrVector(char* data, int max) { | 178 inline Vector<char> MutableCStrVector(char* data, int max) { |
193 int length = StrLength(data); | 179 int length = StrLength(data); |
194 return Vector<char>(data, (length < max) ? length : max); | 180 return Vector<char>(data, (length < max) ? length : max); |
195 } | 181 } |
196 | 182 |
197 | 183 |
198 } } // namespace v8::internal | 184 } } // namespace v8::internal |
199 | 185 |
200 #endif // V8_VECTOR_H_ | 186 #endif // V8_VECTOR_H_ |
OLD | NEW |