mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-22 11:44:17 +01:00
Codechange: replace 'new PoolItem(...' with 'PoolItem::Create(...'
This commit is contained in:
@@ -288,16 +288,8 @@ public:
|
||||
/** Type of the pool this item is going to be part of */
|
||||
typedef struct Pool<Titem, Tindex, Tgrowth_step, Tpool_type, Tcache> Pool;
|
||||
|
||||
/**
|
||||
* Allocates space for new Titem
|
||||
* @param size size of Titem
|
||||
* @return pointer to allocated memory
|
||||
* @note can never fail (return nullptr), use CanAllocate() to check first!
|
||||
*/
|
||||
inline void *operator new(size_t size)
|
||||
{
|
||||
return Tpool->GetNew(size);
|
||||
}
|
||||
/** Do not use new PoolItem, but rather PoolItem::Create. */
|
||||
inline void *operator new(size_t) = delete;
|
||||
|
||||
/**
|
||||
* Marks Titem as free. Its memory is released
|
||||
@@ -347,6 +339,19 @@ public:
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new T-object in the associated pool.
|
||||
* @param args... The arguments to the constructor.
|
||||
* @return The created object.
|
||||
*/
|
||||
template <typename T = Titem, typename... Targs>
|
||||
requires std::is_base_of_v<Titem, T>
|
||||
static inline T *Create(Targs &&... args)
|
||||
{
|
||||
void *data = Tpool->GetNew(sizeof(T));
|
||||
return ::new (data) T(std::forward<Targs&&>(args)...);
|
||||
}
|
||||
|
||||
/** Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user