| 8745 | } |
| 8746 | |
| 8747 | void VmaBlockMetadata_Linear::CleanupAfterFree() |
| 8748 | { |
| 8749 | SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8750 | SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8751 | |
| 8752 | if (IsEmpty()) |
| 8753 | { |
| 8754 | suballocations1st.clear(); |
| 8755 | suballocations2nd.clear(); |
| 8756 | m_1stNullItemsBeginCount = 0; |
| 8757 | m_1stNullItemsMiddleCount = 0; |
| 8758 | m_2ndNullItemsCount = 0; |
| 8759 | m_2ndVectorMode = SECOND_VECTOR_EMPTY; |
| 8760 | } |
| 8761 | else |
| 8762 | { |
| 8763 | const size_t suballoc1stCount = suballocations1st.size(); |
| 8764 | const size_t nullItem1stCount = m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount; |
| 8765 | VMA_ASSERT(nullItem1stCount <= suballoc1stCount); |
| 8766 | |
| 8767 | // Find more null items at the beginning of 1st vector. |
| 8768 | while (m_1stNullItemsBeginCount < suballoc1stCount && |
| 8769 | suballocations1st[m_1stNullItemsBeginCount].type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8770 | { |
| 8771 | ++m_1stNullItemsBeginCount; |
| 8772 | --m_1stNullItemsMiddleCount; |
| 8773 | } |
| 8774 | |
| 8775 | // Find more null items at the end of 1st vector. |
| 8776 | while (m_1stNullItemsMiddleCount > 0 && |
| 8777 | suballocations1st.back().type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8778 | { |
| 8779 | --m_1stNullItemsMiddleCount; |
| 8780 | suballocations1st.pop_back(); |
| 8781 | } |
| 8782 | |
| 8783 | // Find more null items at the end of 2nd vector. |
| 8784 | while (m_2ndNullItemsCount > 0 && |
| 8785 | suballocations2nd.back().type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8786 | { |
| 8787 | --m_2ndNullItemsCount; |
| 8788 | suballocations2nd.pop_back(); |
| 8789 | } |
| 8790 | |
| 8791 | // Find more null items at the beginning of 2nd vector. |
| 8792 | while (m_2ndNullItemsCount > 0 && |
| 8793 | suballocations2nd[0].type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8794 | { |
| 8795 | --m_2ndNullItemsCount; |
| 8796 | VmaVectorRemove(suballocations2nd, 0); |
| 8797 | } |
| 8798 | |
| 8799 | if (ShouldCompact1st()) |
| 8800 | { |
| 8801 | const size_t nonNullItemCount = suballoc1stCount - nullItem1stCount; |
| 8802 | size_t srcIndex = m_1stNullItemsBeginCount; |
| 8803 | for (size_t dstIndex = 0; dstIndex < nonNullItemCount; ++dstIndex) |
| 8804 | { |