Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions include/common/DynamicPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace com
typename std::vector<T>::iterator getLastActive() noexcept;

protected:
void put_(T value, FindValueCallback findValueCallback) noexcept;
template<typename SwapFn>
void put_(T value, FindValueCallback findValueCallback, SwapFn swap) noexcept;

std::vector<T>& getStorage() { return m_storage; }

Expand Down Expand Up @@ -159,11 +160,13 @@ namespace com
{
auto lastActiveEnd = std::next(getLastActive(), 1);
return std::find(m_storage.begin(), lastActiveEnd, value);;
});
},
[](auto&& a, auto&& b) { std::swap(std::forward<decltype(a)>(a), std::forward<decltype(b)>(b)); });
}

template<typename T>
void DynamicPool<T>::put_(T value, FindValueCallback findValueCallback) noexcept
template<typename SwapFn>
void DynamicPool<T>::put_(T value, FindValueCallback findValueCallback, SwapFn swap) noexcept
{
_com_assert(m_activeCount > 0);

Expand All @@ -178,7 +181,7 @@ namespace com
*it = std::move(value);

// If yes then swap this value with the last active value
std::swap(*it, *lastActive);
swap(*it, *lastActive);
m_onReturn(*lastActive);
--m_activeCount;
}
Expand Down
5 changes: 5 additions & 0 deletions include/common/DynamicPoolFast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ namespace com
DynamicPool<DynamicPoolFastElement<T>>::put_(std::move(el), [this](const DynamicPoolFastElement<T>& el)
{
return std::next(DynamicPool<DynamicPoolFastElement<T>>::getStorage().begin(), el.getIndex());
},
[](auto&& a, auto&& b)
{
std::swap(a.m_index, b.m_index);
std::swap(std::forward<decltype(a)>(a), std::forward<decltype(b)>(b));
});
}
};
Expand Down
Loading