| 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> | |
| 294 struct VectorTypeOperations { | 274 struct VectorTypeOperations { |
| 295 STATIC_ONLY(VectorTypeOperations); | 275 STATIC_ONLY(VectorTypeOperations); |
| 296 static void destruct(T* begin, T* end) | 276 static void destruct(T* begin, T* end) |
| 297 { | 277 { |
| 298 VectorDestructor<VectorTraits<T>::needsDestruction, T>::destruct(begin,
end); | 278 VectorDestructor<VectorTraits<T>::needsDestruction, T>::destruct(begin,
end); |
| 299 } | 279 } |
| 300 | 280 |
| 301 static void initialize(T* begin, T* end) | 281 static void initialize(T* begin, T* end) |
| 302 { | 282 { |
| 303 VectorInitializer<VectorTraits<T>::canInitializeWithMemset, T>::initiali
ze(begin, end); | 283 VectorInitializer<VectorTraits<T>::canInitializeWithMemset, T>::initiali
ze(begin, end); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 325 | 305 |
| 326 static void uninitializedFill(T* dst, T* dstEnd, const T& val) | 306 static void uninitializedFill(T* dst, T* dstEnd, const T& val) |
| 327 { | 307 { |
| 328 VectorFiller<VectorTraits<T>::canFillWithMemset, T>::uninitializedFill(d
st, dstEnd, val); | 308 VectorFiller<VectorTraits<T>::canFillWithMemset, T>::uninitializedFill(d
st, dstEnd, val); |
| 329 } | 309 } |
| 330 | 310 |
| 331 static bool compare(const T* a, const T* b, size_t size) | 311 static bool compare(const T* a, const T* b, size_t size) |
| 332 { | 312 { |
| 333 return VectorComparer<VectorTraits<T>::canCompareWithMemcmp, T>::compare
(a, b, size); | 313 return VectorComparer<VectorTraits<T>::canCompareWithMemcmp, T>::compare
(a, b, size); |
| 334 } | 314 } |
| 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 } | |
| 341 }; | 315 }; |
| 342 | 316 |
| 343 template <typename T, bool hasInlineCapacity, typename Allocator> | 317 template <typename T, bool hasInlineCapacity, typename Allocator> |
| 344 class VectorBufferBase { | 318 class VectorBufferBase { |
| 345 WTF_MAKE_NONCOPYABLE(VectorBufferBase); | 319 WTF_MAKE_NONCOPYABLE(VectorBufferBase); |
| 346 DISALLOW_NEW(); | 320 DISALLOW_NEW(); |
| 347 public: | 321 public: |
| 348 void allocateBuffer(size_t newCapacity) | 322 void allocateBuffer(size_t newCapacity) |
| 349 { | 323 { |
| 350 ASSERT(newCapacity); | 324 ASSERT(newCapacity); |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 return find(value) != kNotFound; | 1088 return find(value) != kNotFound; |
| 1115 } | 1089 } |
| 1116 | 1090 |
| 1117 template <typename T, size_t inlineCapacity, typename Allocator> | 1091 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1118 template <typename U> | 1092 template <typename U> |
| 1119 size_t Vector<T, inlineCapacity, Allocator>::find(const U& value) const | 1093 size_t Vector<T, inlineCapacity, Allocator>::find(const U& value) const |
| 1120 { | 1094 { |
| 1121 const T* b = begin(); | 1095 const T* b = begin(); |
| 1122 const T* e = end(); | 1096 const T* e = end(); |
| 1123 for (const T* iter = b; iter < e; ++iter) { | 1097 for (const T* iter = b; iter < e; ++iter) { |
| 1124 if (TypeOperations::compareElement(*iter, value)) | 1098 if (*iter == value) |
| 1125 return iter - b; | 1099 return iter - b; |
| 1126 } | 1100 } |
| 1127 return kNotFound; | 1101 return kNotFound; |
| 1128 } | 1102 } |
| 1129 | 1103 |
| 1130 template <typename T, size_t inlineCapacity, typename Allocator> | 1104 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1131 template <typename U> | 1105 template <typename U> |
| 1132 size_t Vector<T, inlineCapacity, Allocator>::reverseFind(const U& value) const | 1106 size_t Vector<T, inlineCapacity, Allocator>::reverseFind(const U& value) const |
| 1133 { | 1107 { |
| 1134 const T* b = begin(); | 1108 const T* b = begin(); |
| 1135 const T* iter = end(); | 1109 const T* iter = end(); |
| 1136 while (iter > b) { | 1110 while (iter > b) { |
| 1137 --iter; | 1111 --iter; |
| 1138 if (TypeOperations::compareElement(*iter, value)) | 1112 if (*iter == value) |
| 1139 return iter - b; | 1113 return iter - b; |
| 1140 } | 1114 } |
| 1141 return kNotFound; | 1115 return kNotFound; |
| 1142 } | 1116 } |
| 1143 | 1117 |
| 1144 template <typename T, size_t inlineCapacity, typename Allocator> | 1118 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1145 void Vector<T, inlineCapacity, Allocator>::fill(const T& val, size_t newSize) | 1119 void Vector<T, inlineCapacity, Allocator>::fill(const T& val, size_t newSize) |
| 1146 { | 1120 { |
| 1147 if (size() > newSize) { | 1121 if (size() > newSize) { |
| 1148 shrink(newSize); | 1122 shrink(newSize); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis
itor, *const_cast<T*>(bufferEntry)); | 1528 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis
itor, *const_cast<T*>(bufferEntry)); |
| 1555 checkUnusedSlots(buffer() + size(), buffer() + capacity()); | 1529 checkUnusedSlots(buffer() + size(), buffer() + capacity()); |
| 1556 } | 1530 } |
| 1557 } | 1531 } |
| 1558 | 1532 |
| 1559 } // namespace WTF | 1533 } // namespace WTF |
| 1560 | 1534 |
| 1561 using WTF::Vector; | 1535 using WTF::Vector; |
| 1562 | 1536 |
| 1563 #endif // WTF_Vector_h | 1537 #endif // WTF_Vector_h |
| OLD | NEW |