Remove redundant if:

currentBlock and prevPhysical block can't be free at the same time at this moment.
This commit is contained in:
Pavel Gribov 2025-01-25 23:24:45 +03:00
parent 72c309a83b
commit 4ad5e3b4c1

View file

@ -9318,40 +9318,21 @@ void VmaBlockMetadata_TLSF::Alloc(
VkDeviceSize debugMargin = GetDebugMargin(); VkDeviceSize debugMargin = GetDebugMargin();
VkDeviceSize missingAlignment = offset - currentBlock->offset; VkDeviceSize missingAlignment = offset - currentBlock->offset;
// Append missing alignment to prev block or create new one // Create new block for missing alignment
if (missingAlignment) if (missingAlignment)
{ {
Block* prevBlock = currentBlock->prevPhysical; Block* prevBlock = currentBlock->prevPhysical;
VMA_ASSERT(prevBlock != VMA_NULL && "There should be no missing alignment at offset 0!"); VMA_ASSERT(prevBlock != VMA_NULL && "There should be no missing alignment at offset 0!");
if (prevBlock->IsFree() && prevBlock->size != debugMargin) Block* newBlock = m_BlockAllocator.Alloc();
{ currentBlock->prevPhysical = newBlock;
uint32_t oldList = GetListIndex(prevBlock->size); prevBlock->nextPhysical = newBlock;
prevBlock->size += missingAlignment; newBlock->prevPhysical = prevBlock;
// Check if new size crosses list bucket newBlock->nextPhysical = currentBlock;
if (oldList != GetListIndex(prevBlock->size)) newBlock->size = missingAlignment;
{ newBlock->offset = currentBlock->offset;
prevBlock->size -= missingAlignment; newBlock->MarkTaken();
RemoveFreeBlock(prevBlock); InsertFreeBlock(newBlock);
prevBlock->size += missingAlignment;
InsertFreeBlock(prevBlock);
}
else
m_BlocksFreeSize += missingAlignment;
}
else
{
Block* newBlock = m_BlockAllocator.Alloc();
currentBlock->prevPhysical = newBlock;
prevBlock->nextPhysical = newBlock;
newBlock->prevPhysical = prevBlock;
newBlock->nextPhysical = currentBlock;
newBlock->size = missingAlignment;
newBlock->offset = currentBlock->offset;
newBlock->MarkTaken();
InsertFreeBlock(newBlock);
}
currentBlock->size -= missingAlignment; currentBlock->size -= missingAlignment;
currentBlock->offset += missingAlignment; currentBlock->offset += missingAlignment;