A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
This commit is contained in:
@ -42,21 +42,21 @@
|
||||
|
||||
enum {
|
||||
|
||||
POOL_ALLOCATOR_INVALID_ID=-1 ///< default invalid value. use INVALID_ID( id ) to test
|
||||
POOL_ALLOCATOR_INVALID_ID = -1 ///< default invalid value. use INVALID_ID( id ) to test
|
||||
};
|
||||
|
||||
class PoolAllocator {
|
||||
public:
|
||||
typedef int ID;
|
||||
|
||||
private:
|
||||
enum {
|
||||
CHECK_BITS=8,
|
||||
CHECK_LEN=(1<<CHECK_BITS),
|
||||
CHECK_MASK=CHECK_LEN-1
|
||||
CHECK_BITS = 8,
|
||||
CHECK_LEN = (1 << CHECK_BITS),
|
||||
CHECK_MASK = CHECK_LEN - 1
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct Entry {
|
||||
|
||||
unsigned int pos;
|
||||
@ -64,11 +64,15 @@ private:
|
||||
unsigned int lock;
|
||||
unsigned int check;
|
||||
|
||||
inline void clear() { pos=0; len=0; lock=0; check=0; }
|
||||
inline void clear() {
|
||||
pos = 0;
|
||||
len = 0;
|
||||
lock = 0;
|
||||
check = 0;
|
||||
}
|
||||
Entry() { clear(); }
|
||||
};
|
||||
|
||||
|
||||
typedef int EntryArrayPos;
|
||||
typedef int EntryIndicesPos;
|
||||
|
||||
@ -89,40 +93,40 @@ private:
|
||||
|
||||
bool needs_locking;
|
||||
|
||||
inline int entry_end(const Entry& p_entry) const {
|
||||
return p_entry.pos+aligned(p_entry.len);
|
||||
inline int entry_end(const Entry &p_entry) const {
|
||||
return p_entry.pos + aligned(p_entry.len);
|
||||
}
|
||||
inline int aligned(int p_size) const {
|
||||
|
||||
int rem=p_size%align;
|
||||
int rem = p_size % align;
|
||||
if (rem)
|
||||
p_size+=align-rem;
|
||||
p_size += align - rem;
|
||||
|
||||
return p_size;
|
||||
}
|
||||
|
||||
void compact(int p_up_to=-1);
|
||||
void compact_up(int p_from=0);
|
||||
bool get_free_entry(EntryArrayPos* p_pos);
|
||||
void compact(int p_up_to = -1);
|
||||
void compact_up(int p_from = 0);
|
||||
bool get_free_entry(EntryArrayPos *p_pos);
|
||||
bool find_hole(EntryArrayPos *p_pos, int p_for_size);
|
||||
bool find_entry_index(EntryIndicesPos *p_map_pos,Entry *p_entry);
|
||||
Entry* get_entry(ID p_mem);
|
||||
const Entry* get_entry(ID p_mem) const;
|
||||
bool find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry);
|
||||
Entry *get_entry(ID p_mem);
|
||||
const Entry *get_entry(ID p_mem) const;
|
||||
|
||||
void create_pool(void *p_mem, int p_size, int p_max_entries);
|
||||
|
||||
void create_pool(void * p_mem,int p_size,int p_max_entries);
|
||||
protected:
|
||||
virtual void mt_lock() const; ///< Reimplement for custom mt locking
|
||||
virtual void mt_unlock() const; ///< Reimplement for custom mt locking
|
||||
|
||||
public:
|
||||
|
||||
enum {
|
||||
DEFAULT_MAX_ALLOCS=4096,
|
||||
DEFAULT_MAX_ALLOCS = 4096,
|
||||
};
|
||||
|
||||
ID alloc(int p_size); ///< Alloc memory, get an ID on success, POOL_ALOCATOR_INVALID_ID on failure
|
||||
void free(ID p_mem); ///< Free allocated memory
|
||||
Error resize(ID p_mem,int p_new_size); ///< resize a memory chunk
|
||||
Error resize(ID p_mem, int p_new_size); ///< resize a memory chunk
|
||||
int get_size(ID p_mem) const;
|
||||
|
||||
int get_free_mem(); ///< get free memory
|
||||
@ -135,12 +139,11 @@ public:
|
||||
void unlock(ID p_mem);
|
||||
bool is_locked(ID p_mem) const;
|
||||
|
||||
PoolAllocator(int p_size,bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS);
|
||||
PoolAllocator(void * p_mem,int p_size, int p_align = 1, bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS);
|
||||
PoolAllocator(int p_align,int p_size,bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS);
|
||||
PoolAllocator(int p_size, bool p_needs_locking = false, int p_max_entries = DEFAULT_MAX_ALLOCS);
|
||||
PoolAllocator(void *p_mem, int p_size, int p_align = 1, bool p_needs_locking = false, int p_max_entries = DEFAULT_MAX_ALLOCS);
|
||||
PoolAllocator(int p_align, int p_size, bool p_needs_locking = false, int p_max_entries = DEFAULT_MAX_ALLOCS);
|
||||
|
||||
virtual ~PoolAllocator();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user