Chromium Code Reviews| 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) { | |
|
aandrey
2014/07/01 09:49:11
bool operator==() const {
marja
2014/07/01 11:33:58
Done.
| |
| 104 if (length_ != other.length_) return false; | |
|
aandrey
2014/07/01 09:49:11
if (this == &other) return true; ?
marja
2014/07/01 11:33:58
I think this is even better:
if (start_ == other.s
| |
| 105 for (int i = 0; i < length_; ++i) { | |
| 106 if (start_[i] != other.start_[i]) { | |
| 107 return false; | |
| 108 } | |
| 109 } | |
| 110 return true; | |
| 111 } | |
| 112 | |
| 103 protected: | 113 protected: |
| 104 void set_start(T* start) { start_ = start; } | 114 void set_start(T* start) { start_ = start; } |
| 105 | 115 |
| 106 private: | 116 private: |
| 107 T* start_; | 117 T* start_; |
| 108 int length_; | 118 int length_; |
| 109 | 119 |
| 110 class RawComparer { | 120 class RawComparer { |
| 111 public: | 121 public: |
| 112 explicit RawComparer(int (*cmp)(const T*, const T*)) : cmp_(cmp) {} | 122 explicit RawComparer(int (*cmp)(const T*, const T*)) : cmp_(cmp) {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 172 |
| 163 inline Vector<char> MutableCStrVector(char* data, int max) { | 173 inline Vector<char> MutableCStrVector(char* data, int max) { |
| 164 int length = StrLength(data); | 174 int length = StrLength(data); |
| 165 return Vector<char>(data, (length < max) ? length : max); | 175 return Vector<char>(data, (length < max) ? length : max); |
| 166 } | 176 } |
| 167 | 177 |
| 168 | 178 |
| 169 } } // namespace v8::internal | 179 } } // namespace v8::internal |
| 170 | 180 |
| 171 #endif // V8_VECTOR_H_ | 181 #endif // V8_VECTOR_H_ |
| OLD | NEW |