From 5938c0e3950b5d9a15e54d798ba488b34a36eae4 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Thu, 24 Jan 2019 17:30:36 +0100 Subject: [PATCH] Minor refactoring in function VmaBlockMetadata_Generic::CreateAllocationRequest. --- src/vk_mem_alloc.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index f3ce342..9c262ec 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -7959,9 +7959,7 @@ bool VmaBlockMetadata_Generic::CreateAllocationRequest( { // Brute-force algorithm. TODO: Come up with something better. - pAllocationRequest->sumFreeSize = VK_WHOLE_SIZE; - pAllocationRequest->sumItemSize = VK_WHOLE_SIZE; - + bool found = false; VmaAllocationRequest tmpAllocRequest = {}; tmpAllocRequest.type = VmaAllocationRequestType::Normal; for(VmaSuballocationList::iterator suballocIt = m_Suballocations.begin(); @@ -7985,21 +7983,23 @@ bool VmaBlockMetadata_Generic::CreateAllocationRequest( &tmpAllocRequest.sumFreeSize, &tmpAllocRequest.sumItemSize)) { - tmpAllocRequest.item = suballocIt; - - if(tmpAllocRequest.CalcCost() < pAllocationRequest->CalcCost() || - strategy == VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT) + if(strategy == VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT) { *pAllocationRequest = tmpAllocRequest; + pAllocationRequest->item = suballocIt; + break; + } + if(!found || tmpAllocRequest.CalcCost() < pAllocationRequest->CalcCost()) + { + *pAllocationRequest = tmpAllocRequest; + pAllocationRequest->item = suballocIt; + found = true; } } } } - if(pAllocationRequest->sumItemSize != VK_WHOLE_SIZE) - { - return true; - } + return found; } return false;