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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 }; | 328 }; |
329 | 329 |
330 template <typename T, bool hasInlineCapacity, typename Allocator> | 330 template <typename T, bool hasInlineCapacity, typename Allocator> |
331 class VectorBufferBase { | 331 class VectorBufferBase { |
332 WTF_MAKE_NONCOPYABLE(VectorBufferBase); | 332 WTF_MAKE_NONCOPYABLE(VectorBufferBase); |
333 DISALLOW_NEW(); | 333 DISALLOW_NEW(); |
334 | 334 |
335 public: | 335 public: |
336 void allocateBuffer(size_t newCapacity) { | 336 void allocateBuffer(size_t newCapacity) { |
337 DCHECK(newCapacity); | 337 DCHECK(newCapacity); |
| 338 DCHECK_LE(newCapacity, |
| 339 Allocator::template maxElementCountInBackingStore<T>()); |
338 size_t sizeToAllocate = allocationSize(newCapacity); | 340 size_t sizeToAllocate = allocationSize(newCapacity); |
339 if (hasInlineCapacity) | 341 if (hasInlineCapacity) |
340 m_buffer = | 342 m_buffer = |
341 Allocator::template allocateInlineVectorBacking<T>(sizeToAllocate); | 343 Allocator::template allocateInlineVectorBacking<T>(sizeToAllocate); |
342 else | 344 else |
343 m_buffer = Allocator::template allocateVectorBacking<T>(sizeToAllocate); | 345 m_buffer = Allocator::template allocateVectorBacking<T>(sizeToAllocate); |
344 m_capacity = sizeToAllocate / sizeof(T); | 346 m_capacity = sizeToAllocate / sizeof(T); |
345 } | 347 } |
346 | 348 |
347 void allocateExpandedBuffer(size_t newCapacity) { | 349 void allocateExpandedBuffer(size_t newCapacity) { |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 | 992 |
991 template <typename Iterator> | 993 template <typename Iterator> |
992 void appendRange(Iterator start, Iterator end); | 994 void appendRange(Iterator start, Iterator end); |
993 | 995 |
994 void swap(Vector& other) { | 996 void swap(Vector& other) { |
995 Base::swapVectorBuffer(other, OffsetRange(), OffsetRange()); | 997 Base::swapVectorBuffer(other, OffsetRange(), OffsetRange()); |
996 } | 998 } |
997 | 999 |
998 void reverse(); | 1000 void reverse(); |
999 | 1001 |
| 1002 // Maximum element count supported; allocating a vector |
| 1003 // buffer with a larger count will fail. |
| 1004 static size_t maxCapacity() { |
| 1005 return Allocator::template maxElementCountInBackingStore<T>(); |
| 1006 } |
| 1007 |
1000 template <typename VisitorDispatcher> | 1008 template <typename VisitorDispatcher> |
1001 void trace(VisitorDispatcher); | 1009 void trace(VisitorDispatcher); |
1002 | 1010 |
1003 class GCForbiddenScope { | 1011 class GCForbiddenScope { |
1004 STACK_ALLOCATED(); | 1012 STACK_ALLOCATED(); |
1005 | 1013 |
1006 public: | 1014 public: |
1007 GCForbiddenScope() { Allocator::enterGCForbiddenScope(); } | 1015 GCForbiddenScope() { Allocator::enterGCForbiddenScope(); } |
1008 ~GCForbiddenScope() { Allocator::leaveGCForbiddenScope(); } | 1016 ~GCForbiddenScope() { Allocator::leaveGCForbiddenScope(); } |
1009 }; | 1017 }; |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 visitor, *const_cast<T*>(bufferEntry)); | 1619 visitor, *const_cast<T*>(bufferEntry)); |
1612 checkUnusedSlots(buffer() + size(), buffer() + capacity()); | 1620 checkUnusedSlots(buffer() + size(), buffer() + capacity()); |
1613 } | 1621 } |
1614 } | 1622 } |
1615 | 1623 |
1616 } // namespace WTF | 1624 } // namespace WTF |
1617 | 1625 |
1618 using WTF::Vector; | 1626 using WTF::Vector; |
1619 | 1627 |
1620 #endif // WTF_Vector_h | 1628 #endif // WTF_Vector_h |
OLD | NEW |