| 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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 capacity_ = new_size / sizeof(T); | 595 capacity_ = new_size / sizeof(T); |
| 596 return true; | 596 return true; |
| 597 } | 597 } |
| 598 | 598 |
| 599 void ResetBufferPointer() { | 599 void ResetBufferPointer() { |
| 600 buffer_ = InlineBuffer(); | 600 buffer_ = InlineBuffer(); |
| 601 capacity_ = inlineCapacity; | 601 capacity_ = inlineCapacity; |
| 602 } | 602 } |
| 603 | 603 |
| 604 void AllocateBuffer(size_t new_capacity) { | 604 void AllocateBuffer(size_t new_capacity) { |
| 605 // FIXME: This should DCHECK(!m_buffer) to catch misuse/leaks. | 605 // FIXME: This should DCHECK(!buffer_) to catch misuse/leaks. |
| 606 if (new_capacity > inlineCapacity) | 606 if (new_capacity > inlineCapacity) |
| 607 Base::AllocateBuffer(new_capacity); | 607 Base::AllocateBuffer(new_capacity); |
| 608 else | 608 else |
| 609 ResetBufferPointer(); | 609 ResetBufferPointer(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 void AllocateExpandedBuffer(size_t new_capacity) { | 612 void AllocateExpandedBuffer(size_t new_capacity) { |
| 613 if (new_capacity > inlineCapacity) | 613 if (new_capacity > inlineCapacity) |
| 614 Base::AllocateExpandedBuffer(new_capacity); | 614 Base::AllocateExpandedBuffer(new_capacity); |
| 615 else | 615 else |
| (...skipping 10 matching lines...) Expand all Loading... |
| 626 // capacity. | 626 // capacity. |
| 627 // | 627 // |
| 628 // If the data is in an out-of-line buffer, we can just pass the pointers | 628 // If the data is in an out-of-line buffer, we can just pass the pointers |
| 629 // across the two buffers. If the data is in an inline buffer, we need to | 629 // across the two buffers. If the data is in an inline buffer, we need to |
| 630 // either swap or move each element, depending on whether each slot is | 630 // either swap or move each element, depending on whether each slot is |
| 631 // occupied or not. | 631 // occupied or not. |
| 632 // | 632 // |
| 633 // Further complication comes from the fact that VectorBuffer is also used as | 633 // Further complication comes from the fact that VectorBuffer is also used as |
| 634 // the backing store of a Deque. Deque allocates the objects like a ring | 634 // the backing store of a Deque. Deque allocates the objects like a ring |
| 635 // buffer, so there may be a "hole" (unallocated region) in the middle of the | 635 // buffer, so there may be a "hole" (unallocated region) in the middle of the |
| 636 // buffer. This function assumes elements in a range [m_buffer, m_buffer + | 636 // buffer. This function assumes elements in a range [buffer_, buffer_ + |
| 637 // m_size) are all allocated except for elements within |thisHole|. The same | 637 // size_) are all allocated except for elements within |thisHole|. The same |
| 638 // applies for |other.m_buffer| and |otherHole|. | 638 // applies for |other.buffer_| and |otherHole|. |
| 639 void SwapVectorBuffer(VectorBuffer<T, inlineCapacity, Allocator>& other, | 639 void SwapVectorBuffer(VectorBuffer<T, inlineCapacity, Allocator>& other, |
| 640 OffsetRange this_hole, | 640 OffsetRange this_hole, |
| 641 OffsetRange other_hole) { | 641 OffsetRange other_hole) { |
| 642 using TypeOperations = VectorTypeOperations<T>; | 642 using TypeOperations = VectorTypeOperations<T>; |
| 643 | 643 |
| 644 static_assert(VectorTraits<T>::kCanSwapUsingCopyOrMove, | 644 static_assert(VectorTraits<T>::kCanSwapUsingCopyOrMove, |
| 645 "Cannot swap HeapVectors of TraceWrapperMembers."); | 645 "Cannot swap HeapVectors of TraceWrapperMembers."); |
| 646 | 646 |
| 647 if (Buffer() != InlineBuffer() && other.Buffer() != other.InlineBuffer()) { | 647 if (Buffer() != InlineBuffer() && other.Buffer() != other.InlineBuffer()) { |
| 648 // The easiest case: both buffers are non-inline. We just need to swap the | 648 // The easiest case: both buffers are non-inline. We just need to swap the |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 // a local variable. | 865 // a local variable. |
| 866 // | 866 // |
| 867 // In this context, pointers or references to an element of a Vector are | 867 // In this context, pointers or references to an element of a Vector are |
| 868 // essentially equivalent to iterators, in that they also become invalid | 868 // essentially equivalent to iterators, in that they also become invalid |
| 869 // whenever corresponding iterators are invalidated. | 869 // whenever corresponding iterators are invalidated. |
| 870 // | 870 // |
| 871 // 2. Inline buffer | 871 // 2. Inline buffer |
| 872 // | 872 // |
| 873 // Vectors may have an _inline buffer_. An inline buffer is a storage area | 873 // Vectors may have an _inline buffer_. An inline buffer is a storage area |
| 874 // that is contained in the vector itself, along with other metadata like | 874 // that is contained in the vector itself, along with other metadata like |
| 875 // m_size. It is used as a storage space when the vector's elements fit in | 875 // size_. It is used as a storage space when the vector's elements fit in |
| 876 // that space. If the inline buffer becomes full and further space is | 876 // that space. If the inline buffer becomes full and further space is |
| 877 // necessary, an out-of-line buffer is allocated in the heap, and it will | 877 // necessary, an out-of-line buffer is allocated in the heap, and it will |
| 878 // take over the role of the inline buffer. | 878 // take over the role of the inline buffer. |
| 879 // | 879 // |
| 880 // The existence of an inline buffer is indicated by non-zero |inlineCapacity| | 880 // The existence of an inline buffer is indicated by non-zero |inlineCapacity| |
| 881 // template argument. The value represents the number of elements that can be | 881 // template argument. The value represents the number of elements that can be |
| 882 // stored in the inline buffer. Zero |inlineCapacity| means the vector has no | 882 // stored in the inline buffer. Zero |inlineCapacity| means the vector has no |
| 883 // inline buffer. | 883 // inline buffer. |
| 884 // | 884 // |
| 885 // An inline buffer increases the size of the Vector instances, and, in trade | 885 // An inline buffer increases the size of the Vector instances, and, in trade |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 // vector's capacity is large enough for the append to succeed. | 1744 // vector's capacity is large enough for the append to succeed. |
| 1745 template <typename T, size_t inlineCapacity, typename Allocator> | 1745 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1746 template <typename U> | 1746 template <typename U> |
| 1747 ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::UncheckedAppend( | 1747 ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::UncheckedAppend( |
| 1748 U&& val) { | 1748 U&& val) { |
| 1749 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 1749 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
| 1750 // Vectors in ASAN builds don't have inlineCapacity. | 1750 // Vectors in ASAN builds don't have inlineCapacity. |
| 1751 push_back(std::forward<U>(val)); | 1751 push_back(std::forward<U>(val)); |
| 1752 #else | 1752 #else |
| 1753 DCHECK_LT(size(), capacity()); | 1753 DCHECK_LT(size(), capacity()); |
| 1754 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size + 1); | |
| 1755 new (NotNull, end()) T(std::forward<U>(val)); | 1754 new (NotNull, end()) T(std::forward<U>(val)); |
| 1756 ++size_; | 1755 ++size_; |
| 1757 #endif | 1756 #endif |
| 1758 } | 1757 } |
| 1759 | 1758 |
| 1760 template <typename T, size_t inlineCapacity, typename Allocator> | 1759 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1761 template <typename U> | 1760 template <typename U> |
| 1762 inline void Vector<T, inlineCapacity, Allocator>::insert(size_t position, | 1761 inline void Vector<T, inlineCapacity, Allocator>::insert(size_t position, |
| 1763 U&& val) { | 1762 U&& val) { |
| 1764 DCHECK(Allocator::IsAllocationAllowed()); | 1763 DCHECK(Allocator::IsAllocationAllowed()); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 visitor, *const_cast<T*>(buffer_entry)); | 1912 visitor, *const_cast<T*>(buffer_entry)); |
| 1914 CheckUnusedSlots(Buffer() + size(), Buffer() + capacity()); | 1913 CheckUnusedSlots(Buffer() + size(), Buffer() + capacity()); |
| 1915 } | 1914 } |
| 1916 } | 1915 } |
| 1917 | 1916 |
| 1918 } // namespace WTF | 1917 } // namespace WTF |
| 1919 | 1918 |
| 1920 using WTF::Vector; | 1919 using WTF::Vector; |
| 1921 | 1920 |
| 1922 #endif // WTF_Vector_h | 1921 #endif // WTF_Vector_h |
| OLD | NEW |