Minor refactoring

This commit is contained in:
Adam Sawicki 2019-06-03 10:57:56 +02:00
parent 8458ccee39
commit 8d6e6dea2d

View File

@ -3819,7 +3819,7 @@ Returned value is the found element, if present in the collection or place where
new element with value (key) should be inserted. new element with value (key) should be inserted.
*/ */
template <typename CmpLess, typename IterT, typename KeyT> template <typename CmpLess, typename IterT, typename KeyT>
static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT &key, CmpLess cmp) static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT &key, const CmpLess& cmp)
{ {
size_t down = 0, up = (end - beg); size_t down = 0, up = (end - beg);
while(down < up) while(down < up)
@ -3837,6 +3837,19 @@ static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT &key, Cm
return beg + down; return beg + down;
} }
template<typename CmpLess, typename IterT, typename KeyT>
IterT VmaBinaryFindSorted(const IterT& beg, const IterT& end, const KeyT& value, const CmpLess& cmp)
{
IterT it = VmaBinaryFindFirstNotLess<CmpLess, IterT, KeyT>(
beg, end, value, cmp);
if(it == end ||
(!cmp(*it, value) && !cmp(value, *it)))
{
return it;
}
return end;
}
/* /*
Returns true if all pointers in the array are not-null and unique. Returns true if all pointers in the array are not-null and unique.
Warning! O(n^2) complexity. Use only inside VMA_HEAVY_ASSERT. Warning! O(n^2) complexity. Use only inside VMA_HEAVY_ASSERT.
@ -4228,20 +4241,6 @@ bool VmaVectorRemoveSorted(VectorT& vector, const typename VectorT::value_type&
return false; return false;
} }
template<typename CmpLess, typename IterT, typename KeyT>
IterT VmaVectorFindSorted(const IterT& beg, const IterT& end, const KeyT& value)
{
CmpLess comparator;
IterT it = VmaBinaryFindFirstNotLess<CmpLess, IterT, KeyT>(
beg, end, value, comparator);
if(it == end ||
(!comparator(*it, value) && !comparator(value, *it)))
{
return it;
}
return end;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// class VmaPoolAllocator // class VmaPoolAllocator
@ -6858,7 +6857,6 @@ private:
size_t allocationCount, size_t allocationCount,
VmaAllocation* pAllocations); VmaAllocation* pAllocations);
// Tries to free pMemory as Dedicated Memory. Returns true if found and freed.
void FreeDedicatedMemory(VmaAllocation allocation); void FreeDedicatedMemory(VmaAllocation allocation);
/* /*
@ -10433,10 +10431,11 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset)
VmaSuballocation refSuballoc; VmaSuballocation refSuballoc;
refSuballoc.offset = offset; refSuballoc.offset = offset;
// Rest of members stays uninitialized intentionally for better performance. // Rest of members stays uninitialized intentionally for better performance.
SuballocationVectorType::iterator it = VmaVectorFindSorted<VmaSuballocationOffsetLess>( SuballocationVectorType::iterator it = VmaBinaryFindSorted(
suballocations1st.begin() + m_1stNullItemsBeginCount, suballocations1st.begin() + m_1stNullItemsBeginCount,
suballocations1st.end(), suballocations1st.end(),
refSuballoc); refSuballoc,
VmaSuballocationOffsetLess());
if(it != suballocations1st.end()) if(it != suballocations1st.end())
{ {
it->type = VMA_SUBALLOCATION_TYPE_FREE; it->type = VMA_SUBALLOCATION_TYPE_FREE;
@ -10455,8 +10454,8 @@ void VmaBlockMetadata_Linear::FreeAtOffset(VkDeviceSize offset)
refSuballoc.offset = offset; refSuballoc.offset = offset;
// Rest of members stays uninitialized intentionally for better performance. // Rest of members stays uninitialized intentionally for better performance.
SuballocationVectorType::iterator it = m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER ? SuballocationVectorType::iterator it = m_2ndVectorMode == SECOND_VECTOR_RING_BUFFER ?
VmaVectorFindSorted<VmaSuballocationOffsetLess>(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc) : VmaBinaryFindSorted(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc, VmaSuballocationOffsetLess()) :
VmaVectorFindSorted<VmaSuballocationOffsetGreater>(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc); VmaBinaryFindSorted(suballocations2nd.begin(), suballocations2nd.end(), refSuballoc, VmaSuballocationOffsetGreater());
if(it != suballocations2nd.end()) if(it != suballocations2nd.end())
{ {
it->type = VMA_SUBALLOCATION_TYPE_FREE; it->type = VMA_SUBALLOCATION_TYPE_FREE;