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(newCapacity <= | |
Yuta Kitamura
2017/01/30 07:19:42
nit+optional: Use DCHECK_LE?
sof
2017/01/31 21:01:43
yes, done.
| |
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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
992 | 994 |
993 template <typename Iterator> | 995 template <typename Iterator> |
994 void appendRange(Iterator start, Iterator end); | 996 void appendRange(Iterator start, Iterator end); |
995 | 997 |
996 void swap(Vector& other) { | 998 void swap(Vector& other) { |
997 Base::swapVectorBuffer(other, OffsetRange(), OffsetRange()); | 999 Base::swapVectorBuffer(other, OffsetRange(), OffsetRange()); |
998 } | 1000 } |
999 | 1001 |
1000 void reverse(); | 1002 void reverse(); |
1001 | 1003 |
1004 // Maximum element count supported; allocating a vector | |
1005 // buffer with a larger count will fail. | |
1006 static size_t maxCapacity() { | |
1007 return Allocator::template maxElementCountInBackingStore<T>(); | |
1008 } | |
1009 | |
1002 template <typename VisitorDispatcher> | 1010 template <typename VisitorDispatcher> |
1003 void trace(VisitorDispatcher); | 1011 void trace(VisitorDispatcher); |
1004 | 1012 |
1005 class GCForbiddenScope { | 1013 class GCForbiddenScope { |
1006 STACK_ALLOCATED(); | 1014 STACK_ALLOCATED(); |
1007 | 1015 |
1008 public: | 1016 public: |
1009 GCForbiddenScope() { Allocator::enterGCForbiddenScope(); } | 1017 GCForbiddenScope() { Allocator::enterGCForbiddenScope(); } |
1010 ~GCForbiddenScope() { Allocator::leaveGCForbiddenScope(); } | 1018 ~GCForbiddenScope() { Allocator::leaveGCForbiddenScope(); } |
1011 }; | 1019 }; |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1619 visitor, *const_cast<T*>(bufferEntry)); | 1627 visitor, *const_cast<T*>(bufferEntry)); |
1620 checkUnusedSlots(buffer() + size(), buffer() + capacity()); | 1628 checkUnusedSlots(buffer() + size(), buffer() + capacity()); |
1621 } | 1629 } |
1622 } | 1630 } |
1623 | 1631 |
1624 } // namespace WTF | 1632 } // namespace WTF |
1625 | 1633 |
1626 using WTF::Vector; | 1634 using WTF::Vector; |
1627 | 1635 |
1628 #endif // WTF_Vector_h | 1636 #endif // WTF_Vector_h |
OLD | NEW |