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 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1587 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 1587 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
1588 size_t old_capacity = Capacity(); | 1588 size_t old_capacity = Capacity(); |
1589 #endif | 1589 #endif |
1590 // The Allocator::isGarbageCollected check is not needed. The check is just | 1590 // The Allocator::isGarbageCollected check is not needed. The check is just |
1591 // a static hint for a compiler to indicate that Base::expandBuffer returns | 1591 // a static hint for a compiler to indicate that Base::expandBuffer returns |
1592 // false if Allocator is a PartitionAllocator. | 1592 // false if Allocator is a PartitionAllocator. |
1593 if (Allocator::kIsGarbageCollected && Base::ExpandBuffer(new_capacity)) { | 1593 if (Allocator::kIsGarbageCollected && Base::ExpandBuffer(new_capacity)) { |
1594 ANNOTATE_CHANGE_CAPACITY(begin(), old_capacity, size_, Capacity()); | 1594 ANNOTATE_CHANGE_CAPACITY(begin(), old_capacity, size_, Capacity()); |
1595 return; | 1595 return; |
1596 } | 1596 } |
1597 // Reallocating a backing buffer may resurrect a dead object. | |
1598 CHECK(!Allocator::IsObjectResurrectionForbidden()); | |
1599 | |
1597 T* old_end = end(); | 1600 T* old_end = end(); |
1598 Base::AllocateExpandedBuffer(new_capacity); | 1601 Base::AllocateExpandedBuffer(new_capacity); |
1599 ANNOTATE_NEW_BUFFER(begin(), Capacity(), size_); | 1602 ANNOTATE_NEW_BUFFER(begin(), Capacity(), size_); |
1600 TypeOperations::Move(old_buffer, old_end, begin()); | 1603 TypeOperations::Move(old_buffer, old_end, begin()); |
1601 ClearUnusedSlots(old_buffer, old_end); | 1604 ClearUnusedSlots(old_buffer, old_end); |
1602 ANNOTATE_DELETE_BUFFER(old_buffer, old_capacity, size_); | 1605 ANNOTATE_DELETE_BUFFER(old_buffer, old_capacity, size_); |
1603 Base::DeallocateBuffer(old_buffer); | 1606 Base::DeallocateBuffer(old_buffer); |
1604 } | 1607 } |
1605 | 1608 |
1606 template <typename T, size_t inlineCapacity, typename Allocator> | 1609 template <typename T, size_t inlineCapacity, typename Allocator> |
1607 inline void Vector<T, inlineCapacity, Allocator>::ReserveInitialCapacity( | 1610 inline void Vector<T, inlineCapacity, Allocator>::ReserveInitialCapacity( |
1608 size_t initial_capacity) { | 1611 size_t initial_capacity) { |
1609 DCHECK(!size_); | 1612 DCHECK(!size_); |
1610 DCHECK(Capacity() == INLINE_CAPACITY); | 1613 DCHECK(Capacity() == INLINE_CAPACITY); |
1611 if (initial_capacity > INLINE_CAPACITY) { | 1614 if (initial_capacity > INLINE_CAPACITY) { |
1612 ANNOTATE_DELETE_BUFFER(begin(), Capacity(), size_); | 1615 ANNOTATE_DELETE_BUFFER(begin(), Capacity(), size_); |
1613 Base::AllocateBuffer(initial_capacity); | 1616 Base::AllocateBuffer(initial_capacity); |
1614 ANNOTATE_NEW_BUFFER(begin(), Capacity(), size_); | 1617 ANNOTATE_NEW_BUFFER(begin(), Capacity(), size_); |
1615 } | 1618 } |
1616 } | 1619 } |
1617 | 1620 |
1618 template <typename T, size_t inlineCapacity, typename Allocator> | 1621 template <typename T, size_t inlineCapacity, typename Allocator> |
1619 void Vector<T, inlineCapacity, Allocator>::ShrinkCapacity(size_t new_capacity) { | 1622 void Vector<T, inlineCapacity, Allocator>::ShrinkCapacity(size_t new_capacity) { |
1620 if (new_capacity >= Capacity()) | 1623 if (new_capacity >= Capacity()) |
1621 return; | 1624 return; |
1622 | 1625 |
1623 if (new_capacity < size()) | 1626 if (new_capacity < size()) |
1624 Shrink(new_capacity); | 1627 Shrink(new_capacity); |
1625 | 1628 |
1629 if (Allocator::IsObjectResurrectionForbidden()) | |
sof
2017/04/15 18:57:31
Why leave early for the new_capacity == 0 case?
keishi
2017/04/17 06:37:55
Created fix at https://codereview.chromium.org/281
| |
1630 return; | |
1631 | |
1626 T* old_buffer = begin(); | 1632 T* old_buffer = begin(); |
1627 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 1633 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
1628 size_t old_capacity = Capacity(); | 1634 size_t old_capacity = Capacity(); |
1629 #endif | 1635 #endif |
1630 if (new_capacity > 0) { | 1636 if (new_capacity > 0) { |
1631 if (Base::ShrinkBuffer(new_capacity)) { | 1637 if (Base::ShrinkBuffer(new_capacity)) { |
1632 ANNOTATE_CHANGE_CAPACITY(begin(), old_capacity, size_, Capacity()); | 1638 ANNOTATE_CHANGE_CAPACITY(begin(), old_capacity, size_, Capacity()); |
1633 return; | 1639 return; |
1634 } | 1640 } |
1635 | 1641 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1907 visitor, *const_cast<T*>(buffer_entry)); | 1913 visitor, *const_cast<T*>(buffer_entry)); |
1908 CheckUnusedSlots(Buffer() + size(), Buffer() + Capacity()); | 1914 CheckUnusedSlots(Buffer() + size(), Buffer() + Capacity()); |
1909 } | 1915 } |
1910 } | 1916 } |
1911 | 1917 |
1912 } // namespace WTF | 1918 } // namespace WTF |
1913 | 1919 |
1914 using WTF::Vector; | 1920 using WTF::Vector; |
1915 | 1921 |
1916 #endif // WTF_Vector_h | 1922 #endif // WTF_Vector_h |
OLD | NEW |