Cleanup: Various clang-tidy warnings in intern
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
This commit is contained in:
@@ -10,27 +10,27 @@
|
||||
#define __MEM_ALLOCATOR_H__
|
||||
|
||||
#include "guardedalloc/MEM_guardedalloc.h"
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
template<typename _Tp> struct MEM_Allocator {
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef _Tp *pointer;
|
||||
typedef const _Tp *const_pointer;
|
||||
typedef _Tp &reference;
|
||||
typedef const _Tp &const_reference;
|
||||
typedef _Tp value_type;
|
||||
using size_type = size_t;
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = _Tp *;
|
||||
using const_pointer = const _Tp *;
|
||||
using reference = _Tp &;
|
||||
using const_reference = const _Tp &;
|
||||
using value_type = _Tp;
|
||||
|
||||
template<typename _Tp1> struct rebind {
|
||||
typedef MEM_Allocator<_Tp1> other;
|
||||
using other = MEM_Allocator<_Tp1>;
|
||||
};
|
||||
|
||||
MEM_Allocator() throw() {}
|
||||
MEM_Allocator(const MEM_Allocator &) throw() {}
|
||||
MEM_Allocator() noexcept = default;
|
||||
MEM_Allocator(const MEM_Allocator & /*other*/) noexcept = default;
|
||||
|
||||
template<typename _Tp1> MEM_Allocator(const MEM_Allocator<_Tp1>) throw() {}
|
||||
template<typename _Tp1> MEM_Allocator(const MEM_Allocator<_Tp1> /*other*/) noexcept {}
|
||||
|
||||
~MEM_Allocator() throw() {}
|
||||
~MEM_Allocator() noexcept = default;
|
||||
|
||||
pointer address(reference __x) const
|
||||
{
|
||||
@@ -44,7 +44,7 @@ template<typename _Tp> struct MEM_Allocator {
|
||||
|
||||
/* NOTE: `__n` is permitted to be 0.
|
||||
* The C++ standard says nothing about what the return value is when `__n == 0`. */
|
||||
_Tp *allocate(size_type __n, const void * = 0)
|
||||
_Tp *allocate(size_type __n, const void * /*unused*/ = nullptr)
|
||||
{
|
||||
_Tp *__ret = NULL;
|
||||
if (__n) {
|
||||
@@ -54,12 +54,12 @@ template<typename _Tp> struct MEM_Allocator {
|
||||
}
|
||||
|
||||
// __p is not permitted to be a null pointer.
|
||||
void deallocate(pointer __p, size_type)
|
||||
void deallocate(pointer __p, size_type /*unused*/)
|
||||
{
|
||||
MEM_freeN(__p);
|
||||
}
|
||||
|
||||
size_type max_size() const throw()
|
||||
size_type max_size() const noexcept
|
||||
{
|
||||
return size_t(-1) / sizeof(_Tp);
|
||||
}
|
||||
|
||||
@@ -42,8 +42,6 @@
|
||||
*/
|
||||
|
||||
#include "MEM_Allocator.h"
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
template<class T> class MEM_CacheLimiter;
|
||||
@@ -60,7 +58,7 @@ bool MEM_CacheLimiter_is_disabled(void);
|
||||
template<class T> class MEM_CacheLimiterHandle {
|
||||
public:
|
||||
explicit MEM_CacheLimiterHandle(T *data_, MEM_CacheLimiter<T> *parent_)
|
||||
: data(data_), refcount(0), parent(parent_)
|
||||
: data(data_), parent(parent_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -119,16 +117,16 @@ template<class T> class MEM_CacheLimiterHandle {
|
||||
friend class MEM_CacheLimiter<T>;
|
||||
|
||||
T *data;
|
||||
int refcount;
|
||||
int refcount = 0;
|
||||
int pos;
|
||||
MEM_CacheLimiter<T> *parent;
|
||||
};
|
||||
|
||||
template<class T> class MEM_CacheLimiter {
|
||||
public:
|
||||
typedef size_t (*MEM_CacheLimiter_DataSize_Func)(void *data);
|
||||
typedef int (*MEM_CacheLimiter_ItemPriority_Func)(void *item, int default_priority);
|
||||
typedef bool (*MEM_CacheLimiter_ItemDestroyable_Func)(void *item);
|
||||
using MEM_CacheLimiter_DataSize_Func = size_t (*)(void *);
|
||||
using MEM_CacheLimiter_ItemPriority_Func = int (*)(void *, int);
|
||||
using MEM_CacheLimiter_ItemDestroyable_Func = bool (*)(void *);
|
||||
|
||||
MEM_CacheLimiter(MEM_CacheLimiter_DataSize_Func data_size_func) : data_size_func(data_size_func)
|
||||
{
|
||||
@@ -224,7 +222,7 @@ template<class T> class MEM_CacheLimiter {
|
||||
* doesn't make much sense because we'll iterate it all to get
|
||||
* least priority element anyway.
|
||||
*/
|
||||
if (item_priority_func == NULL) {
|
||||
if (item_priority_func == nullptr) {
|
||||
queue[handle->pos] = queue.back();
|
||||
queue[handle->pos]->pos = handle->pos;
|
||||
queue.pop_back();
|
||||
@@ -244,9 +242,9 @@ template<class T> class MEM_CacheLimiter {
|
||||
}
|
||||
|
||||
private:
|
||||
typedef MEM_CacheLimiterHandle<T> *MEM_CacheElementPtr;
|
||||
typedef std::vector<MEM_CacheElementPtr, MEM_Allocator<MEM_CacheElementPtr>> MEM_CacheQueue;
|
||||
typedef typename MEM_CacheQueue::iterator iterator;
|
||||
using MEM_CacheElementPtr = MEM_CacheLimiterHandle<T> *;
|
||||
using MEM_CacheQueue = std::vector<MEM_CacheElementPtr, MEM_Allocator<MEM_CacheElementPtr>>;
|
||||
using iterator = typename MEM_CacheQueue::iterator;
|
||||
|
||||
/* Check whether element can be destroyed when enforcing cache limits */
|
||||
bool can_destroy_element(MEM_CacheElementPtr &elem)
|
||||
@@ -263,7 +261,7 @@ template<class T> class MEM_CacheLimiter {
|
||||
return true;
|
||||
}
|
||||
|
||||
MEM_CacheElementPtr get_least_priority_destroyable_element(void)
|
||||
MEM_CacheElementPtr get_least_priority_destroyable_element()
|
||||
{
|
||||
if (queue.empty()) {
|
||||
return NULL;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef __MEM_CACHELIMITERC_API_H__
|
||||
#define __MEM_CACHELIMITERC_API_H__
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include <cstddef>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -18,20 +18,20 @@ extern "C" {
|
||||
struct MEM_CacheLimiter_s;
|
||||
struct MEM_CacheLimiterHandle_s;
|
||||
|
||||
typedef struct MEM_CacheLimiter_s MEM_CacheLimiterC;
|
||||
typedef struct MEM_CacheLimiterHandle_s MEM_CacheLimiterHandleC;
|
||||
using MEM_CacheLimiterC = struct MEM_CacheLimiter_s;
|
||||
using MEM_CacheLimiterHandleC = struct MEM_CacheLimiterHandle_s;
|
||||
|
||||
/* function used to remove data from memory */
|
||||
typedef void (*MEM_CacheLimiter_Destruct_Func)(void *);
|
||||
using MEM_CacheLimiter_Destruct_Func = void (*)(void *);
|
||||
|
||||
/* function used to measure stored data element size */
|
||||
typedef size_t (*MEM_CacheLimiter_DataSize_Func)(void *);
|
||||
using MEM_CacheLimiter_DataSize_Func = size_t (*)(void *);
|
||||
|
||||
/* function used to measure priority of item when freeing memory */
|
||||
typedef int (*MEM_CacheLimiter_ItemPriority_Func)(void *, int);
|
||||
using MEM_CacheLimiter_ItemPriority_Func = int (*)(void *, int);
|
||||
|
||||
/* function to check whether item could be destroyed */
|
||||
typedef bool (*MEM_CacheLimiter_ItemDestroyable_Func)(void *);
|
||||
using MEM_CacheLimiter_ItemDestroyable_Func = bool (*)(void *);
|
||||
|
||||
#ifndef __MEM_CACHELIMITER_H__
|
||||
void MEM_CacheLimiter_set_maximum(size_t m);
|
||||
|
||||
@@ -27,7 +27,7 @@ class MEM_RefCounted {
|
||||
/**
|
||||
* Constructs a shared object.
|
||||
*/
|
||||
MEM_RefCounted() : m_refCount(1) {}
|
||||
MEM_RefCounted() = default;
|
||||
|
||||
/**
|
||||
* Returns the reference count of this object.
|
||||
@@ -53,11 +53,10 @@ class MEM_RefCounted {
|
||||
* Destructs a shared object.
|
||||
* The destructor is protected to force the use of incRef and decRef.
|
||||
*/
|
||||
virtual ~MEM_RefCounted() {}
|
||||
virtual ~MEM_RefCounted() = default;
|
||||
|
||||
protected:
|
||||
/** The reference count. */
|
||||
int m_refCount;
|
||||
int m_refCount = 1;
|
||||
};
|
||||
|
||||
inline int MEM_RefCounted::getRef() const
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#define __MEM_REFCOUNTEDC_API_H__
|
||||
|
||||
/** A pointer to a private object. */
|
||||
typedef struct MEM_TOpaqueObject *MEM_TObjectPtr;
|
||||
using MEM_TObjectPtr = struct MEM_TOpaqueObject *;
|
||||
/** A pointer to a shared object. */
|
||||
typedef MEM_TObjectPtr MEM_TRefCountedObjectPtr;
|
||||
using MEM_TRefCountedObjectPtr = MEM_TObjectPtr;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <list>
|
||||
|
||||
#include "MEM_CacheLimiter.h"
|
||||
#include "MEM_CacheLimiterC-Api.h"
|
||||
@@ -42,10 +43,10 @@ bool MEM_CacheLimiter_is_disabled(void)
|
||||
class MEM_CacheLimiterHandleCClass;
|
||||
class MEM_CacheLimiterCClass;
|
||||
|
||||
typedef MEM_CacheLimiterHandle<MEM_CacheLimiterHandleCClass> handle_t;
|
||||
typedef MEM_CacheLimiter<MEM_CacheLimiterHandleCClass> cache_t;
|
||||
typedef std::list<MEM_CacheLimiterHandleCClass *, MEM_Allocator<MEM_CacheLimiterHandleCClass *>>
|
||||
list_t;
|
||||
using handle_t = MEM_CacheLimiterHandle<MEM_CacheLimiterHandleCClass>;
|
||||
using cache_t = MEM_CacheLimiter<MEM_CacheLimiterHandleCClass>;
|
||||
using list_t =
|
||||
std::list<MEM_CacheLimiterHandleCClass *, MEM_Allocator<MEM_CacheLimiterHandleCClass *>>;
|
||||
|
||||
class MEM_CacheLimiterCClass {
|
||||
public:
|
||||
@@ -130,7 +131,7 @@ MEM_CacheLimiterCClass::~MEM_CacheLimiterCClass()
|
||||
{
|
||||
// should not happen, but don't leak memory in this case...
|
||||
for (list_t::iterator it = cclass_list.begin(); it != cclass_list.end(); it++) {
|
||||
(*it)->set_data(NULL);
|
||||
(*it)->set_data(nullptr);
|
||||
|
||||
delete *it;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user