Codechange: remove transitional supports from the pool
This commit is contained in:
@@ -23,8 +23,9 @@
|
||||
* @param type The return type of the method.
|
||||
*/
|
||||
#define DEFINE_POOL_METHOD(type) \
|
||||
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type, bool Tcache, bool Tzero> \
|
||||
type Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero>
|
||||
template <class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type, bool Tcache, bool Tzero> \
|
||||
requires std::is_base_of_v<PoolIDBase, Tindex> \
|
||||
type Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache, Tzero>
|
||||
|
||||
/**
|
||||
* Create a clean pool.
|
||||
@@ -47,15 +48,15 @@ DEFINE_POOL_METHOD(inline)::Pool(const char *name) :
|
||||
* Resizes the pool so 'index' can be addressed
|
||||
* @param index index we will allocate later
|
||||
* @pre index >= this->size
|
||||
* @pre index < Tmax_size
|
||||
* @pre index < MAX_SIZE
|
||||
*/
|
||||
DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index)
|
||||
{
|
||||
assert(index >= this->data.size());
|
||||
assert(index < Tmax_size);
|
||||
assert(index < MAX_SIZE);
|
||||
|
||||
size_t old_size = this->data.size();
|
||||
size_t new_size = std::min(Tmax_size, Align(index + 1, Tgrowth_step));
|
||||
size_t new_size = std::min(MAX_SIZE, Align(index + 1, Tgrowth_step));
|
||||
|
||||
this->data.resize(new_size);
|
||||
this->used_bitmap.resize(Align(new_size, BITMAP_SIZE) / BITMAP_SIZE);
|
||||
@@ -83,12 +84,12 @@ DEFINE_POOL_METHOD(inline size_t)::FindFirstFree()
|
||||
|
||||
assert(this->first_unused == this->data.size());
|
||||
|
||||
if (this->first_unused < Tmax_size) {
|
||||
if (this->first_unused < MAX_SIZE) {
|
||||
this->ResizeFor(this->first_unused);
|
||||
return this->first_unused;
|
||||
}
|
||||
|
||||
assert(this->first_unused == Tmax_size);
|
||||
assert(this->first_unused == MAX_SIZE);
|
||||
|
||||
return NO_FREE_ITEM;
|
||||
}
|
||||
@@ -124,12 +125,8 @@ DEFINE_POOL_METHOD(inline void *)::AllocateItem(size_t size, size_t index)
|
||||
}
|
||||
this->data[index] = item;
|
||||
SetBit(this->used_bitmap[index / BITMAP_SIZE], index % BITMAP_SIZE);
|
||||
if constexpr (std::is_base_of_v<PoolIDBase, Tindex>) {
|
||||
/* MSVC complains about casting to narrower type, so first cast to the base type... then to the strong type. */
|
||||
item->index = static_cast<Tindex>(static_cast<Tindex::BaseType>(index));
|
||||
} else {
|
||||
item->index = static_cast<Tindex>(index);
|
||||
}
|
||||
/* MSVC complains about casting to narrower type, so first cast to the base type... then to the strong type. */
|
||||
item->index = static_cast<Tindex>(static_cast<Tindex::BaseType>(index));
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -164,8 +161,8 @@ DEFINE_POOL_METHOD(void *)::GetNew(size_t size)
|
||||
*/
|
||||
DEFINE_POOL_METHOD(void *)::GetNew(size_t size, size_t index)
|
||||
{
|
||||
if (index >= Tmax_size) {
|
||||
SlErrorCorruptFmt("{} index {} out of range ({})", this->name, index, Tmax_size);
|
||||
if (index >= MAX_SIZE) {
|
||||
SlErrorCorruptFmt("{} index {} out of range ({})", this->name, index, MAX_SIZE);
|
||||
}
|
||||
|
||||
if (index >= this->data.size()) this->ResizeFor(index);
|
||||
|
||||
@@ -124,27 +124,16 @@ private:
|
||||
* @tparam Titem Type of the class/struct that is going to be pooled
|
||||
* @tparam Tindex Type of the index for this pool
|
||||
* @tparam Tgrowth_step Size of growths; if the pool is full increase the size by this amount
|
||||
* @tparam Tmax_size Maximum size of the pool
|
||||
* @tparam Tpool_type Type of this pool
|
||||
* @tparam Tcache Whether to perform 'alloc' caching, i.e. don't actually free/malloc just reuse the memory
|
||||
* @tparam Tzero Whether to zero the memory
|
||||
* @warning when Tcache is enabled *all* instances of this pool's item must be of the same size.
|
||||
*/
|
||||
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PoolType::Normal, bool Tcache = false, bool Tzero = true>
|
||||
template <class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false, bool Tzero = true>
|
||||
requires std::is_base_of_v<PoolIDBase, Tindex>
|
||||
struct Pool : PoolBase {
|
||||
private:
|
||||
/** Some helper functions to get the maximum value of the provided index. */
|
||||
template <typename T>
|
||||
static constexpr size_t GetMaxIndexValue(T) { return std::numeric_limits<T>::max(); }
|
||||
template <typename T> requires std::is_enum_v<T>
|
||||
static constexpr size_t GetMaxIndexValue(T) { return std::numeric_limits<std::underlying_type_t<T>>::max(); }
|
||||
template <typename T> requires std::is_base_of_v<PoolIDBase, T>
|
||||
static constexpr size_t GetMaxIndexValue(T) { return std::numeric_limits<typename T::BaseType>::max(); }
|
||||
public:
|
||||
/* Ensure the highest possible index, i.e. Tmax_size -1, is within the bounds of Tindex. */
|
||||
static_assert(Tmax_size - 1 <= GetMaxIndexValue(Tindex{}));
|
||||
|
||||
static constexpr size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside
|
||||
static constexpr size_t MAX_SIZE = Tindex::End().base(); ///< Make template parameter accessible from outside
|
||||
|
||||
using BitmapStorage = size_t;
|
||||
static constexpr size_t BITMAP_SIZE = std::numeric_limits<BitmapStorage>::digits;
|
||||
@@ -194,7 +183,7 @@ public:
|
||||
*/
|
||||
inline bool CanAllocate(size_t n = 1)
|
||||
{
|
||||
bool ret = this->items <= Tmax_size - n;
|
||||
bool ret = this->items <= MAX_SIZE - n;
|
||||
#ifdef WITH_ASSERT
|
||||
this->checked = ret ? n : 0;
|
||||
#endif /* WITH_ASSERT */
|
||||
@@ -293,12 +282,12 @@ public:
|
||||
* Base class for all PoolItems
|
||||
* @tparam Tpool The pool this item is going to be part of
|
||||
*/
|
||||
template <struct Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero> *Tpool>
|
||||
template <struct Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache, Tzero> *Tpool>
|
||||
struct PoolItem {
|
||||
Tindex index; ///< Index of this pool item
|
||||
|
||||
/** Type of the pool this item is going to be part of */
|
||||
typedef struct Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero> Pool;
|
||||
typedef struct Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache, Tzero> Pool;
|
||||
|
||||
/**
|
||||
* Allocates space for new Titem
|
||||
@@ -472,7 +461,6 @@ private:
|
||||
|
||||
void FreeItem(size_t index);
|
||||
|
||||
/* Temporary helper functions to get the raw index from either strongly and non-strongly typed pool items. */
|
||||
static constexpr size_t GetRawIndex(size_t index) { return index; }
|
||||
template <typename T> requires std::is_base_of_v<PoolIDBase, T>
|
||||
static constexpr size_t GetRawIndex(const T &index) { return index.base(); }
|
||||
|
||||
Reference in New Issue
Block a user