Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: third_party/WebKit/Source/wtf/Vector.h

Issue 2690953002: WTF: Update comments for Vector. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #else 50 #else
51 #ifndef WTF_VECTOR_INITIAL_SIZE 51 #ifndef WTF_VECTOR_INITIAL_SIZE
52 #define WTF_VECTOR_INITIAL_SIZE 4 52 #define WTF_VECTOR_INITIAL_SIZE 4
53 #endif 53 #endif
54 static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; 54 static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
55 #endif 55 #endif
56 56
57 template <typename T, size_t inlineBuffer, typename Allocator> 57 template <typename T, size_t inlineBuffer, typename Allocator>
58 class Deque; 58 class Deque;
59 59
60 //
61 // Vector Traits
62 //
63
64 // Bunch of traits for Vector are defined here, with which you can customize
65 // Vector's behavior. In most cases the default traits are appropriate, so you
66 // usually don't have to specialize those traits by yourself.
67
60 template <bool needsDestruction, typename T> 68 template <bool needsDestruction, typename T>
61 struct VectorDestructor; 69 struct VectorDestructor;
62 70
63 template <typename T> 71 template <typename T>
64 struct VectorDestructor<false, T> { 72 struct VectorDestructor<false, T> {
65 STATIC_ONLY(VectorDestructor); 73 STATIC_ONLY(VectorDestructor);
66 static void destruct(T*, T*) {} 74 static void destruct(T*, T*) {}
67 }; 75 };
68 76
69 template <typename T> 77 template <typename T>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 280
273 template <typename T> 281 template <typename T>
274 struct VectorElementComparer<std::unique_ptr<T>> { 282 struct VectorElementComparer<std::unique_ptr<T>> {
275 STATIC_ONLY(VectorElementComparer); 283 STATIC_ONLY(VectorElementComparer);
276 template <typename U> 284 template <typename U>
277 static bool compareElement(const std::unique_ptr<T>& left, const U& right) { 285 static bool compareElement(const std::unique_ptr<T>& left, const U& right) {
278 return left.get() == right; 286 return left.get() == right;
279 } 287 }
280 }; 288 };
281 289
290 // A collection of all the traits used by Vector. This is basically an
291 // implementation detail of Vector, and you should specialize individual traits
292 // defined above, if you want to customize Vector's behavior.
282 template <typename T> 293 template <typename T>
283 struct VectorTypeOperations { 294 struct VectorTypeOperations {
284 STATIC_ONLY(VectorTypeOperations); 295 STATIC_ONLY(VectorTypeOperations);
285 static void destruct(T* begin, T* end) { 296 static void destruct(T* begin, T* end) {
286 VectorDestructor<VectorTraits<T>::needsDestruction, T>::destruct(begin, 297 VectorDestructor<VectorTraits<T>::needsDestruction, T>::destruct(begin,
287 end); 298 end);
288 } 299 }
289 300
290 static void initialize(T* begin, T* end) { 301 static void initialize(T* begin, T* end) {
291 VectorInitializer<VectorTraits<T>::canInitializeWithMemset, T>::initialize( 302 VectorInitializer<VectorTraits<T>::canInitializeWithMemset, T>::initialize(
(...skipping 28 matching lines...) Expand all
320 a, b, size); 331 a, b, size);
321 } 332 }
322 333
323 template <typename U> 334 template <typename U>
324 static bool compareElement(const T& left, U&& right) { 335 static bool compareElement(const T& left, U&& right) {
325 return VectorElementComparer<T>::compareElement(left, 336 return VectorElementComparer<T>::compareElement(left,
326 std::forward<U>(right)); 337 std::forward<U>(right));
327 } 338 }
328 }; 339 };
329 340
341 //
342 // VectorBuffer
343 //
344
345 // VectorBuffer is an implementation detail of Vector and Deque. It manages
346 // Vector's underlying buffer, and does operations like allocation or
347 // expansion.
348 //
349 // Not meant for general consumption.
350
330 template <typename T, bool hasInlineCapacity, typename Allocator> 351 template <typename T, bool hasInlineCapacity, typename Allocator>
331 class VectorBufferBase { 352 class VectorBufferBase {
332 WTF_MAKE_NONCOPYABLE(VectorBufferBase); 353 WTF_MAKE_NONCOPYABLE(VectorBufferBase);
333 DISALLOW_NEW(); 354 DISALLOW_NEW();
334 355
335 public: 356 public:
336 void allocateBuffer(size_t newCapacity) { 357 void allocateBuffer(size_t newCapacity) {
337 DCHECK(newCapacity); 358 DCHECK(newCapacity);
338 DCHECK_LE(newCapacity, 359 DCHECK_LE(newCapacity,
339 Allocator::template maxElementCountInBackingStore<T>()); 360 Allocator::template maxElementCountInBackingStore<T>());
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 static const size_t m_inlineBufferSize = inlineCapacity * sizeof(T); 809 static const size_t m_inlineBufferSize = inlineCapacity * sizeof(T);
789 T* inlineBuffer() { return reinterpret_cast_ptr<T*>(m_inlineBuffer.buffer); } 810 T* inlineBuffer() { return reinterpret_cast_ptr<T*>(m_inlineBuffer.buffer); }
790 const T* inlineBuffer() const { 811 const T* inlineBuffer() const {
791 return reinterpret_cast_ptr<const T*>(m_inlineBuffer.buffer); 812 return reinterpret_cast_ptr<const T*>(m_inlineBuffer.buffer);
792 } 813 }
793 814
794 AlignedBuffer<m_inlineBufferSize, WTF_ALIGN_OF(T)> m_inlineBuffer; 815 AlignedBuffer<m_inlineBufferSize, WTF_ALIGN_OF(T)> m_inlineBuffer;
795 template <typename U, size_t inlineBuffer, typename V> 816 template <typename U, size_t inlineBuffer, typename V>
796 friend class Deque; 817 friend class Deque;
797 }; 818 };
798 // Heap-allocated vectors with no inlineCapacity never need a destructor. 819
820 //
821 // Vector
822 //
823
799 template <typename T, 824 template <typename T,
800 size_t inlineCapacity = 0, 825 size_t inlineCapacity = 0,
801 typename Allocator = PartitionAllocator> 826 typename Allocator = PartitionAllocator>
802 class Vector 827 class Vector
803 : private VectorBuffer<T, INLINE_CAPACITY, Allocator>, 828 : private VectorBuffer<T, INLINE_CAPACITY, Allocator>,
829 // Heap-allocated vectors with no inlineCapacity never need a destructor.
804 public ConditionalDestructor<Vector<T, INLINE_CAPACITY, Allocator>, 830 public ConditionalDestructor<Vector<T, INLINE_CAPACITY, Allocator>,
805 (INLINE_CAPACITY == 0) && 831 (INLINE_CAPACITY == 0) &&
806 Allocator::isGarbageCollected> { 832 Allocator::isGarbageCollected> {
807 USE_ALLOCATOR(Vector, Allocator); 833 USE_ALLOCATOR(Vector, Allocator);
808 using Base = VectorBuffer<T, INLINE_CAPACITY, Allocator>; 834 using Base = VectorBuffer<T, INLINE_CAPACITY, Allocator>;
809 using TypeOperations = VectorTypeOperations<T>; 835 using TypeOperations = VectorTypeOperations<T>;
810 using OffsetRange = typename Base::OffsetRange; 836 using OffsetRange = typename Base::OffsetRange;
811 837
812 public: 838 public:
813 typedef T ValueType; 839 typedef T ValueType;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 template <typename U> 1059 template <typename U>
1034 void appendSlowCase(U&&); 1060 void appendSlowCase(U&&);
1035 1061
1036 using Base::m_size; 1062 using Base::m_size;
1037 using Base::buffer; 1063 using Base::buffer;
1038 using Base::swapVectorBuffer; 1064 using Base::swapVectorBuffer;
1039 using Base::allocateBuffer; 1065 using Base::allocateBuffer;
1040 using Base::allocationSize; 1066 using Base::allocationSize;
1041 }; 1067 };
1042 1068
1069 //
1070 // Vector out-of-line implementation
1071 //
1072
1043 template <typename T, size_t inlineCapacity, typename Allocator> 1073 template <typename T, size_t inlineCapacity, typename Allocator>
1044 Vector<T, inlineCapacity, Allocator>::Vector(const Vector& other) 1074 Vector<T, inlineCapacity, Allocator>::Vector(const Vector& other)
1045 : Base(other.capacity()) { 1075 : Base(other.capacity()) {
1046 ANNOTATE_NEW_BUFFER(begin(), capacity(), other.size()); 1076 ANNOTATE_NEW_BUFFER(begin(), capacity(), other.size());
1047 m_size = other.size(); 1077 m_size = other.size();
1048 TypeOperations::uninitializedCopy(other.begin(), other.end(), begin()); 1078 TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
1049 } 1079 }
1050 1080
1051 template <typename T, size_t inlineCapacity, typename Allocator> 1081 template <typename T, size_t inlineCapacity, typename Allocator>
1052 template <size_t otherCapacity> 1082 template <size_t otherCapacity>
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 visitor, *const_cast<T*>(bufferEntry)); 1649 visitor, *const_cast<T*>(bufferEntry));
1620 checkUnusedSlots(buffer() + size(), buffer() + capacity()); 1650 checkUnusedSlots(buffer() + size(), buffer() + capacity());
1621 } 1651 }
1622 } 1652 }
1623 1653
1624 } // namespace WTF 1654 } // namespace WTF
1625 1655
1626 using WTF::Vector; 1656 using WTF::Vector;
1627 1657
1628 #endif // WTF_Vector_h 1658 #endif // WTF_Vector_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698