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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #ifndef WTF_Vector_h | 21 #ifndef WTF_Vector_h |
22 #define WTF_Vector_h | 22 #define WTF_Vector_h |
23 | 23 |
24 #include "wtf/Alignment.h" | 24 #include "wtf/Alignment.h" |
25 #include "wtf/ConditionalDestructor.h" | 25 #include "wtf/ConditionalDestructor.h" |
26 #include "wtf/ContainerAnnotations.h" | 26 #include "wtf/ContainerAnnotations.h" |
27 #include "wtf/DefaultAllocator.h" | |
28 #include "wtf/Noncopyable.h" | 27 #include "wtf/Noncopyable.h" |
29 #include "wtf/NotFound.h" | 28 #include "wtf/NotFound.h" |
| 29 #include "wtf/PartitionAllocator.h" |
30 #include "wtf/StdLibExtras.h" | 30 #include "wtf/StdLibExtras.h" |
31 #include "wtf/VectorTraits.h" | 31 #include "wtf/VectorTraits.h" |
32 #include <algorithm> | 32 #include <algorithm> |
33 #include <iterator> | 33 #include <iterator> |
34 #include <string.h> | 34 #include <string.h> |
35 #include <utility> | 35 #include <utility> |
36 | 36 |
37 // For ASAN builds, disable inline buffers completely as they cause various issu
es. | 37 // For ASAN builds, disable inline buffers completely as they cause various issu
es. |
38 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 38 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
39 #define INLINE_CAPACITY 0 | 39 #define INLINE_CAPACITY 0 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 : m_buffer(buffer) | 359 : m_buffer(buffer) |
360 , m_capacity(capacity) | 360 , m_capacity(capacity) |
361 { | 361 { |
362 } | 362 } |
363 | 363 |
364 T* m_buffer; | 364 T* m_buffer; |
365 unsigned m_capacity; | 365 unsigned m_capacity; |
366 unsigned m_size; | 366 unsigned m_size; |
367 }; | 367 }; |
368 | 368 |
369 template <typename T, size_t inlineCapacity, typename Allocator = DefaultAllocat
or> | 369 template <typename T, size_t inlineCapacity, typename Allocator = PartitionAlloc
ator> |
370 class VectorBuffer; | 370 class VectorBuffer; |
371 | 371 |
372 template <typename T, typename Allocator> | 372 template <typename T, typename Allocator> |
373 class VectorBuffer<T, 0, Allocator> : protected VectorBufferBase<T, false, Alloc
ator> { | 373 class VectorBuffer<T, 0, Allocator> : protected VectorBufferBase<T, false, Alloc
ator> { |
374 private: | 374 private: |
375 typedef VectorBufferBase<T, false, Allocator> Base; | 375 typedef VectorBufferBase<T, false, Allocator> Base; |
376 public: | 376 public: |
377 VectorBuffer() | 377 VectorBuffer() |
378 { | 378 { |
379 } | 379 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 607 |
608 static const size_t m_inlineBufferSize = inlineCapacity * sizeof(T); | 608 static const size_t m_inlineBufferSize = inlineCapacity * sizeof(T); |
609 T* inlineBuffer() { return reinterpret_cast_ptr<T*>(m_inlineBuffer.buffer);
} | 609 T* inlineBuffer() { return reinterpret_cast_ptr<T*>(m_inlineBuffer.buffer);
} |
610 const T* inlineBuffer() const { return reinterpret_cast_ptr<const T*>(m_inli
neBuffer.buffer); } | 610 const T* inlineBuffer() const { return reinterpret_cast_ptr<const T*>(m_inli
neBuffer.buffer); } |
611 | 611 |
612 AlignedBuffer<m_inlineBufferSize, WTF_ALIGN_OF(T)> m_inlineBuffer; | 612 AlignedBuffer<m_inlineBufferSize, WTF_ALIGN_OF(T)> m_inlineBuffer; |
613 template <typename U, size_t inlineBuffer, typename V> | 613 template <typename U, size_t inlineBuffer, typename V> |
614 friend class Deque; | 614 friend class Deque; |
615 }; | 615 }; |
616 | 616 |
617 template <typename T, size_t inlineCapacity = 0, typename Allocator = DefaultAll
ocator> // Heap-allocated vectors with no inlineCapacity never need a destructor
. | 617 template <typename T, size_t inlineCapacity = 0, typename Allocator = PartitionA
llocator> // Heap-allocated vectors with no inlineCapacity never need a destruct
or. |
618 class Vector : private VectorBuffer<T, INLINE_CAPACITY, Allocator>, public Condi
tionalDestructor<Vector<T, INLINE_CAPACITY, Allocator>, (INLINE_CAPACITY == 0) &
& Allocator::isGarbageCollected> { | 618 class Vector : private VectorBuffer<T, INLINE_CAPACITY, Allocator>, public Condi
tionalDestructor<Vector<T, INLINE_CAPACITY, Allocator>, (INLINE_CAPACITY == 0) &
& Allocator::isGarbageCollected> { |
619 WTF_USE_ALLOCATOR(Vector, Allocator); | 619 WTF_USE_ALLOCATOR(Vector, Allocator); |
620 typedef VectorBuffer<T, INLINE_CAPACITY, Allocator> Base; | 620 typedef VectorBuffer<T, INLINE_CAPACITY, Allocator> Base; |
621 typedef VectorTypeOperations<T> TypeOperations; | 621 typedef VectorTypeOperations<T> TypeOperations; |
622 | 622 |
623 public: | 623 public: |
624 typedef T ValueType; | 624 typedef T ValueType; |
625 typedef T value_type; | 625 typedef T value_type; |
626 | 626 |
627 typedef T* iterator; | 627 typedef T* iterator; |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 T* oldBuffer = begin(); | 1039 T* oldBuffer = begin(); |
1040 if (!oldBuffer) { | 1040 if (!oldBuffer) { |
1041 Base::allocateBuffer(newCapacity); | 1041 Base::allocateBuffer(newCapacity); |
1042 return; | 1042 return; |
1043 } | 1043 } |
1044 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 1044 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
1045 size_t oldCapacity = capacity(); | 1045 size_t oldCapacity = capacity(); |
1046 #endif | 1046 #endif |
1047 // The Allocator::isGarbageCollected check is not needed. The check is just | 1047 // The Allocator::isGarbageCollected check is not needed. The check is just |
1048 // a static hint for a compiler to indicate that Base::expandBuffer returns | 1048 // a static hint for a compiler to indicate that Base::expandBuffer returns |
1049 // false if Allocator is a DefaultAllocator. | 1049 // false if Allocator is a PartitionAllocator. |
1050 if (Allocator::isGarbageCollected && Base::expandBuffer(newCapacity)) { | 1050 if (Allocator::isGarbageCollected && Base::expandBuffer(newCapacity)) { |
1051 ANNOTATE_CHANGE_CAPACITY(begin(), oldCapacity, m_size, capacity()); | 1051 ANNOTATE_CHANGE_CAPACITY(begin(), oldCapacity, m_size, capacity()); |
1052 return; | 1052 return; |
1053 } | 1053 } |
1054 T* oldEnd = end(); | 1054 T* oldEnd = end(); |
1055 Base::allocateExpandedBuffer(newCapacity); | 1055 Base::allocateExpandedBuffer(newCapacity); |
1056 ANNOTATE_NEW_BUFFER(begin(), capacity(), m_size); | 1056 ANNOTATE_NEW_BUFFER(begin(), capacity(), m_size); |
1057 TypeOperations::move(oldBuffer, oldEnd, begin()); | 1057 TypeOperations::move(oldBuffer, oldEnd, begin()); |
1058 clearUnusedSlots(oldBuffer, oldEnd); | 1058 clearUnusedSlots(oldBuffer, oldEnd); |
1059 ANNOTATE_DELETE_BUFFER(oldBuffer, oldCapacity, m_size); | 1059 ANNOTATE_DELETE_BUFFER(oldBuffer, oldCapacity, m_size); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 struct NeedsTracing<Vector<T, N>> { | 1343 struct NeedsTracing<Vector<T, N>> { |
1344 static const bool value = false; | 1344 static const bool value = false; |
1345 }; | 1345 }; |
1346 #endif | 1346 #endif |
1347 | 1347 |
1348 } // namespace WTF | 1348 } // namespace WTF |
1349 | 1349 |
1350 using WTF::Vector; | 1350 using WTF::Vector; |
1351 | 1351 |
1352 #endif // WTF_Vector_h | 1352 #endif // WTF_Vector_h |
OLD | NEW |