Codechange: Replace C-casts in pool functions. (#12541)

This commit is contained in:
Peter Nelson 2024-04-20 16:50:13 +01:00 committed by GitHub
parent c5ef47ee09
commit b4e00fa738
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -115,17 +115,17 @@ DEFINE_POOL_METHOD(inline void *)::AllocateItem(size_t size, size_t index)
Titem *item;
if (Tcache && this->alloc_cache != nullptr) {
assert(sizeof(Titem) == size);
item = (Titem *)this->alloc_cache;
item = reinterpret_cast<Titem *>(this->alloc_cache);
this->alloc_cache = this->alloc_cache->next;
if (Tzero) {
/* Explicitly casting to (void *) prevents a clang warning -
* we are actually memsetting a (not-yet-constructed) object */
memset((void *)item, 0, sizeof(Titem));
memset(static_cast<void *>(item), 0, sizeof(Titem));
}
} else if (Tzero) {
item = (Titem *)CallocT<uint8_t>(size);
item = reinterpret_cast<Titem *>(CallocT<uint8_t>(size));
} else {
item = (Titem *)MallocT<uint8_t>(size);
item = reinterpret_cast<Titem *>(MallocT<uint8_t>(size));
}
this->data[index] = item;
SetBit(this->used_bitmap[index / BITMAP_SIZE], index % BITMAP_SIZE);
@ -188,7 +188,7 @@ DEFINE_POOL_METHOD(void)::FreeItem(size_t index)
assert(index < this->size);
assert(this->data[index] != nullptr);
if (Tcache) {
AllocCache *ac = (AllocCache *)this->data[index];
AllocCache *ac = reinterpret_cast<AllocCache *>(this->data[index]);
ac->next = this->alloc_cache;
this->alloc_cache = ac;
} else {

View File

@ -78,8 +78,8 @@ private:
*/
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
struct Pool : PoolBase {
/* Ensure Tmax_size is within the bounds of Tindex. */
static_assert((uint64_t)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
/* Ensure the highest possible index, i.e. Tmax_size -1, is within the bounds of Tindex. */
static_assert(Tmax_size - 1 <= MAX_UVALUE(Tindex));
static constexpr size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside
@ -259,7 +259,7 @@ struct Pool : PoolBase {
inline void operator delete(void *p)
{
if (p == nullptr) return;
Titem *pn = (Titem *)p;
Titem *pn = static_cast<Titem *>(p);
assert(pn == Tpool->Get(pn->index));
Tpool->FreeItem(pn->index);
}