| 8450 | } |
| 8451 | |
| 8452 | void VmaBlockMetadata_Linear::CleanupAfterFree() |
| 8453 | { |
| 8454 | SuballocationVectorType& suballocations1st = AccessSuballocations1st(); |
| 8455 | SuballocationVectorType& suballocations2nd = AccessSuballocations2nd(); |
| 8456 | |
| 8457 | if (IsEmpty()) |
| 8458 | { |
| 8459 | suballocations1st.clear(); |
| 8460 | suballocations2nd.clear(); |
| 8461 | m_1stNullItemsBeginCount = 0; |
| 8462 | m_1stNullItemsMiddleCount = 0; |
| 8463 | m_2ndNullItemsCount = 0; |
| 8464 | m_2ndVectorMode = SECOND_VECTOR_EMPTY; |
| 8465 | } |
| 8466 | else |
| 8467 | { |
| 8468 | const size_t suballoc1stCount = suballocations1st.size(); |
| 8469 | const size_t nullItem1stCount = m_1stNullItemsBeginCount + m_1stNullItemsMiddleCount; |
| 8470 | VMA_ASSERT(nullItem1stCount <= suballoc1stCount); |
| 8471 | |
| 8472 | // Find more null items at the beginning of 1st vector. |
| 8473 | while (m_1stNullItemsBeginCount < suballoc1stCount && |
| 8474 | suballocations1st[m_1stNullItemsBeginCount].type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8475 | { |
| 8476 | ++m_1stNullItemsBeginCount; |
| 8477 | --m_1stNullItemsMiddleCount; |
| 8478 | } |
| 8479 | |
| 8480 | // Find more null items at the end of 1st vector. |
| 8481 | while (m_1stNullItemsMiddleCount > 0 && |
| 8482 | suballocations1st.back().type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8483 | { |
| 8484 | --m_1stNullItemsMiddleCount; |
| 8485 | suballocations1st.pop_back(); |
| 8486 | } |
| 8487 | |
| 8488 | // Find more null items at the end of 2nd vector. |
| 8489 | while (m_2ndNullItemsCount > 0 && |
| 8490 | suballocations2nd.back().type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8491 | { |
| 8492 | --m_2ndNullItemsCount; |
| 8493 | suballocations2nd.pop_back(); |
| 8494 | } |
| 8495 | |
| 8496 | // Find more null items at the beginning of 2nd vector. |
| 8497 | while (m_2ndNullItemsCount > 0 && |
| 8498 | suballocations2nd[0].type == VMA_SUBALLOCATION_TYPE_FREE) |
| 8499 | { |
| 8500 | --m_2ndNullItemsCount; |
| 8501 | VmaVectorRemove(suballocations2nd, 0); |
| 8502 | } |
| 8503 | |
| 8504 | if (ShouldCompact1st()) |
| 8505 | { |
| 8506 | const size_t nonNullItemCount = suballoc1stCount - nullItem1stCount; |
| 8507 | size_t srcIndex = m_1stNullItemsBeginCount; |
| 8508 | for (size_t dstIndex = 0; dstIndex < nonNullItemCount; ++dstIndex) |
| 8509 | { |