OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 STATIC_ONLY(VectorComparer); | 264 STATIC_ONLY(VectorComparer); |
265 static bool compare(const T* a, const T* b, size_t size) | 265 static bool compare(const T* a, const T* b, size_t size) |
266 { | 266 { |
267 ASSERT(a); | 267 ASSERT(a); |
268 ASSERT(b); | 268 ASSERT(b); |
269 return memcmp(a, b, sizeof(T) * size) == 0; | 269 return memcmp(a, b, sizeof(T) * size) == 0; |
270 } | 270 } |
271 }; | 271 }; |
272 | 272 |
273 template <typename T> | 273 template <typename T> |
| 274 struct VectorElementComparer { |
| 275 STATIC_ONLY(VectorElementComparer); |
| 276 template <typename U> |
| 277 static bool compareElement(const T& left, const U& right) |
| 278 { |
| 279 return left == right; |
| 280 } |
| 281 }; |
| 282 |
| 283 template <typename T> |
| 284 struct VectorElementComparer<std::unique_ptr<T>> { |
| 285 STATIC_ONLY(VectorElementComparer); |
| 286 template <typename U> |
| 287 static bool compareElement(const std::unique_ptr<T>& left, const U& right) |
| 288 { |
| 289 return left.get() == right; |
| 290 } |
| 291 }; |
| 292 |
| 293 template <typename T> |
274 struct VectorTypeOperations { | 294 struct VectorTypeOperations { |
275 STATIC_ONLY(VectorTypeOperations); | 295 STATIC_ONLY(VectorTypeOperations); |
276 static void destruct(T* begin, T* end) | 296 static void destruct(T* begin, T* end) |
277 { | 297 { |
278 VectorDestructor<VectorTraits<T>::needsDestruction, T>::destruct(begin,
end); | 298 VectorDestructor<VectorTraits<T>::needsDestruction, T>::destruct(begin,
end); |
279 } | 299 } |
280 | 300 |
281 static void initialize(T* begin, T* end) | 301 static void initialize(T* begin, T* end) |
282 { | 302 { |
283 VectorInitializer<VectorTraits<T>::canInitializeWithMemset, T>::initiali
ze(begin, end); | 303 VectorInitializer<VectorTraits<T>::canInitializeWithMemset, T>::initiali
ze(begin, end); |
(...skipping 21 matching lines...) Expand all Loading... |
305 | 325 |
306 static void uninitializedFill(T* dst, T* dstEnd, const T& val) | 326 static void uninitializedFill(T* dst, T* dstEnd, const T& val) |
307 { | 327 { |
308 VectorFiller<VectorTraits<T>::canFillWithMemset, T>::uninitializedFill(d
st, dstEnd, val); | 328 VectorFiller<VectorTraits<T>::canFillWithMemset, T>::uninitializedFill(d
st, dstEnd, val); |
309 } | 329 } |
310 | 330 |
311 static bool compare(const T* a, const T* b, size_t size) | 331 static bool compare(const T* a, const T* b, size_t size) |
312 { | 332 { |
313 return VectorComparer<VectorTraits<T>::canCompareWithMemcmp, T>::compare
(a, b, size); | 333 return VectorComparer<VectorTraits<T>::canCompareWithMemcmp, T>::compare
(a, b, size); |
314 } | 334 } |
| 335 |
| 336 template <typename U> |
| 337 static bool compareElement(const T& left, U&& right) |
| 338 { |
| 339 return VectorElementComparer<T>::compareElement(left, std::forward<U>(ri
ght)); |
| 340 } |
315 }; | 341 }; |
316 | 342 |
317 template <typename T, bool hasInlineCapacity, typename Allocator> | 343 template <typename T, bool hasInlineCapacity, typename Allocator> |
318 class VectorBufferBase { | 344 class VectorBufferBase { |
319 WTF_MAKE_NONCOPYABLE(VectorBufferBase); | 345 WTF_MAKE_NONCOPYABLE(VectorBufferBase); |
320 DISALLOW_NEW(); | 346 DISALLOW_NEW(); |
321 public: | 347 public: |
322 void allocateBuffer(size_t newCapacity) | 348 void allocateBuffer(size_t newCapacity) |
323 { | 349 { |
324 ASSERT(newCapacity); | 350 ASSERT(newCapacity); |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 return find(value) != kNotFound; | 1114 return find(value) != kNotFound; |
1089 } | 1115 } |
1090 | 1116 |
1091 template <typename T, size_t inlineCapacity, typename Allocator> | 1117 template <typename T, size_t inlineCapacity, typename Allocator> |
1092 template <typename U> | 1118 template <typename U> |
1093 size_t Vector<T, inlineCapacity, Allocator>::find(const U& value) const | 1119 size_t Vector<T, inlineCapacity, Allocator>::find(const U& value) const |
1094 { | 1120 { |
1095 const T* b = begin(); | 1121 const T* b = begin(); |
1096 const T* e = end(); | 1122 const T* e = end(); |
1097 for (const T* iter = b; iter < e; ++iter) { | 1123 for (const T* iter = b; iter < e; ++iter) { |
1098 if (*iter == value) | 1124 if (TypeOperations::compareElement(*iter, value)) |
1099 return iter - b; | 1125 return iter - b; |
1100 } | 1126 } |
1101 return kNotFound; | 1127 return kNotFound; |
1102 } | 1128 } |
1103 | 1129 |
1104 template <typename T, size_t inlineCapacity, typename Allocator> | 1130 template <typename T, size_t inlineCapacity, typename Allocator> |
1105 template <typename U> | 1131 template <typename U> |
1106 size_t Vector<T, inlineCapacity, Allocator>::reverseFind(const U& value) const | 1132 size_t Vector<T, inlineCapacity, Allocator>::reverseFind(const U& value) const |
1107 { | 1133 { |
1108 const T* b = begin(); | 1134 const T* b = begin(); |
1109 const T* iter = end(); | 1135 const T* iter = end(); |
1110 while (iter > b) { | 1136 while (iter > b) { |
1111 --iter; | 1137 --iter; |
1112 if (*iter == value) | 1138 if (TypeOperations::compareElement(*iter, value)) |
1113 return iter - b; | 1139 return iter - b; |
1114 } | 1140 } |
1115 return kNotFound; | 1141 return kNotFound; |
1116 } | 1142 } |
1117 | 1143 |
1118 template <typename T, size_t inlineCapacity, typename Allocator> | 1144 template <typename T, size_t inlineCapacity, typename Allocator> |
1119 void Vector<T, inlineCapacity, Allocator>::fill(const T& val, size_t newSize) | 1145 void Vector<T, inlineCapacity, Allocator>::fill(const T& val, size_t newSize) |
1120 { | 1146 { |
1121 if (size() > newSize) { | 1147 if (size() > newSize) { |
1122 shrink(newSize); | 1148 shrink(newSize); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis
itor, *const_cast<T*>(bufferEntry)); | 1554 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis
itor, *const_cast<T*>(bufferEntry)); |
1529 checkUnusedSlots(buffer() + size(), buffer() + capacity()); | 1555 checkUnusedSlots(buffer() + size(), buffer() + capacity()); |
1530 } | 1556 } |
1531 } | 1557 } |
1532 | 1558 |
1533 } // namespace WTF | 1559 } // namespace WTF |
1534 | 1560 |
1535 using WTF::Vector; | 1561 using WTF::Vector; |
1536 | 1562 |
1537 #endif // WTF_Vector_h | 1563 #endif // WTF_Vector_h |
OLD | NEW |