Merge pull request #201 from GermanAizek/patch

Code refactor (lower scope, local var, default constructor and destructor)
diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h
index 5a84798..4463be8 100644
--- a/include/vk_mem_alloc.h
+++ b/include/vk_mem_alloc.h
@@ -3800,11 +3800,9 @@
 }

 

 template<typename T>

-VmaRawList<T>::~VmaRawList()

-{

-    // Intentionally not calling Clear, because that would be unnecessary

-    // computations to return all items to m_ItemAllocator as free.

-}

+VmaRawList<T>::~VmaRawList() = default;

+// Intentionally not calling Clear, because that would be unnecessary

+// computations to return all items to m_ItemAllocator as free.

 

 template<typename T>

 void VmaRawList<T>::Clear()

@@ -4224,7 +4222,7 @@
     static ItemType* GetPrev(const ItemType* item) { return ItemTypeTraits::GetPrev(item); }

     static ItemType* GetNext(const ItemType* item) { return ItemTypeTraits::GetNext(item); }

     // Movable, not copyable.

-    VmaIntrusiveLinkedList() { }

+    VmaIntrusiveLinkedList() = default;

     VmaIntrusiveLinkedList(const VmaIntrusiveLinkedList<ItemTypeTraits>& src) = delete;

     VmaIntrusiveLinkedList(VmaIntrusiveLinkedList<ItemTypeTraits>&& src) :

         m_Front(src.m_Front), m_Back(src.m_Back), m_Count(src.m_Count)

@@ -12225,13 +12223,14 @@
 

         const VkDeviceSize maxBytesToMove = defragmentOnGpu ? maxGpuBytesToMove : maxCpuBytesToMove;

         const uint32_t maxAllocationsToMove = defragmentOnGpu ? maxGpuAllocationsToMove : maxCpuAllocationsToMove;

-        pCtx->res = pCtx->GetAlgorithm()->Defragment(pCtx->defragmentationMoves, maxBytesToMove, maxAllocationsToMove, flags);

+        VmaDefragmentationAlgorithm* algo = pCtx->GetAlgorithm();

+        pCtx->res = algo->Defragment(pCtx->defragmentationMoves, maxBytesToMove, maxAllocationsToMove, flags);

 

         // Accumulate statistics.

         if(pStats != VMA_NULL)

         {

-            const VkDeviceSize bytesMoved = pCtx->GetAlgorithm()->GetBytesMoved();

-            const uint32_t allocationsMoved = pCtx->GetAlgorithm()->GetAllocationsMoved();

+            const VkDeviceSize bytesMoved = algo->GetBytesMoved();

+            const uint32_t allocationsMoved = algo->GetAllocationsMoved();

             pStats->bytesMoved += bytesMoved;

             pStats->allocationsMoved += allocationsMoved;

             VMA_ASSERT(bytesMoved <= maxBytesToMove);

@@ -13072,9 +13071,9 @@
                         freeSize, // size

                         VMA_NULL, // hAllocation

                         VMA_SUBALLOCATION_TYPE_FREE };

-                    VmaSuballocationList::iterator precedingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);

                     if(freeSize >= VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)

                     {

+                        VmaSuballocationList::iterator precedingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);

                         pMetadata->m_FreeSuballocationsBySize.push_back(precedingFreeIt);

                     }

                 }

@@ -13094,9 +13093,9 @@
                     VMA_NULL, // hAllocation

                     VMA_SUBALLOCATION_TYPE_FREE };

                 VMA_ASSERT(it == pMetadata->m_Suballocations.end());

-                VmaSuballocationList::iterator trailingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);

                 if(freeSize > VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER)

                 {

+                    VmaSuballocationList::iterator trailingFreeIt = pMetadata->m_Suballocations.insert(it, suballoc);

                     pMetadata->m_FreeSuballocationsBySize.push_back(trailingFreeIt);

                 }

             }

@@ -16633,12 +16632,13 @@
 

     const VkDevice hDev = allocator->m_hDevice;

     VkBuffer hBuffer = VK_NULL_HANDLE;

-    VkResult res = allocator->GetVulkanFunctions().vkCreateBuffer(

+    const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions();

+    VkResult res = funcs->vkCreateBuffer(

         hDev, pBufferCreateInfo, allocator->GetAllocationCallbacks(), &hBuffer);

     if(res == VK_SUCCESS)

     {

         VkMemoryRequirements memReq = {};

-        allocator->GetVulkanFunctions().vkGetBufferMemoryRequirements(

+        funcs->vkGetBufferMemoryRequirements(

             hDev, hBuffer, &memReq);

 

         res = vmaFindMemoryTypeIndex(

@@ -16647,7 +16647,7 @@
             pAllocationCreateInfo,

             pMemoryTypeIndex);

 

-        allocator->GetVulkanFunctions().vkDestroyBuffer(

+        funcs->vkDestroyBuffer(

             hDev, hBuffer, allocator->GetAllocationCallbacks());

     }

     return res;

@@ -16666,12 +16666,13 @@
 

     const VkDevice hDev = allocator->m_hDevice;

     VkImage hImage = VK_NULL_HANDLE;

-    VkResult res = allocator->GetVulkanFunctions().vkCreateImage(

+    const VmaVulkanFunctions* funcs = &allocator->GetVulkanFunctions();

+    VkResult res = funcs->vkCreateImage(

         hDev, pImageCreateInfo, allocator->GetAllocationCallbacks(), &hImage);

     if(res == VK_SUCCESS)

     {

         VkMemoryRequirements memReq = {};

-        allocator->GetVulkanFunctions().vkGetImageMemoryRequirements(

+        funcs->vkGetImageMemoryRequirements(

             hDev, hImage, &memReq);

 

         res = vmaFindMemoryTypeIndex(

@@ -16680,7 +16681,7 @@
             pAllocationCreateInfo,

             pMemoryTypeIndex);

 

-        allocator->GetVulkanFunctions().vkDestroyImage(

+        funcs->vkDestroyImage(

             hDev, hImage, allocator->GetAllocationCallbacks());

     }

     return res;