| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 // Factory method for creating empty vectors. | 94 // Factory method for creating empty vectors. |
| 95 static Vector<T> empty() { return Vector<T>(NULL, 0); } | 95 static Vector<T> empty() { return Vector<T>(NULL, 0); } |
| 96 | 96 |
| 97 template<typename S> | 97 template<typename S> |
| 98 static Vector<T> cast(Vector<S> input) { | 98 static Vector<T> cast(Vector<S> input) { |
| 99 return Vector<T>(reinterpret_cast<T*>(input.start()), | 99 return Vector<T>(reinterpret_cast<T*>(input.start()), |
| 100 input.length() * sizeof(S) / sizeof(T)); | 100 input.length() * sizeof(S) / sizeof(T)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool operator==(const Vector<T>& other) const { |
| 104 if (length_ != other.length_) return false; |
| 105 if (start_ == other.start_) return true; |
| 106 for (int i = 0; i < length_; ++i) { |
| 107 if (start_[i] != other.start_[i]) { |
| 108 return false; |
| 109 } |
| 110 } |
| 111 return true; |
| 112 } |
| 113 |
| 103 protected: | 114 protected: |
| 104 void set_start(T* start) { start_ = start; } | 115 void set_start(T* start) { start_ = start; } |
| 105 | 116 |
| 106 private: | 117 private: |
| 107 T* start_; | 118 T* start_; |
| 108 int length_; | 119 int length_; |
| 109 | 120 |
| 110 class RawComparer { | 121 class RawComparer { |
| 111 public: | 122 public: |
| 112 explicit RawComparer(int (*cmp)(const T*, const T*)) : cmp_(cmp) {} | 123 explicit RawComparer(int (*cmp)(const T*, const T*)) : cmp_(cmp) {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 173 |
| 163 inline Vector<char> MutableCStrVector(char* data, int max) { | 174 inline Vector<char> MutableCStrVector(char* data, int max) { |
| 164 int length = StrLength(data); | 175 int length = StrLength(data); |
| 165 return Vector<char>(data, (length < max) ? length : max); | 176 return Vector<char>(data, (length < max) ? length : max); |
| 166 } | 177 } |
| 167 | 178 |
| 168 | 179 |
| 169 } } // namespace v8::internal | 180 } } // namespace v8::internal |
| 170 | 181 |
| 171 #endif // V8_VECTOR_H_ | 182 #endif // V8_VECTOR_H_ |
| OLD | NEW |