Skip to content

Commit f2b3f52

Browse files
committed
Correction of comments
1 parent 035bfeb commit f2b3f52

File tree

1 file changed

+40
-59
lines changed

1 file changed

+40
-59
lines changed

include/msgpack/v1/detail/cpp11_zone.hpp

Lines changed: 40 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,54 +25,49 @@ namespace msgpack {
2525
/// @cond
2626
MSGPACK_API_VERSION_NAMESPACE(v1) {
2727
/// @endcond
28-
28+
2929
class zone {
3030
private:
3131
struct finalizer {
3232
finalizer(void (*func)(void*), void* data, finalizer* next): m_func(func), m_data(data), m_next(next) {}
3333
void operator()() { m_func(m_data); }
3434
void (*m_func)(void*);
3535
void* m_data;
36-
finalizer* m_next{};
36+
finalizer* m_next;
3737
};
3838
struct finalizer_array {
3939
finalizer_array(): m_head(MSGPACK_NULLPTR) {}
4040

41-
void call(bool clear = false) {
41+
~finalizer_array() {
42+
clear();
43+
}
44+
45+
void clear() {
4246
finalizer* fin = m_head;
4347
finalizer* tmp = nullptr;
4448
while(fin) {
4549
(*fin)();
46-
if (clear) {
47-
tmp = fin;
48-
}
50+
tmp = fin;
4951
fin = fin->m_next;
50-
if (clear) {
51-
delete tmp;
52-
}
52+
delete tmp;
5353
}
54-
}
55-
~finalizer_array() {
56-
clear();
57-
}
58-
void clear() {
59-
call(true);
6054
m_head = MSGPACK_NULLPTR;
6155
}
62-
void push(void (*func)(void* data), void* data)
63-
{
56+
57+
void push(void (*func)(void* data), void* data) {
6458
m_head = new finalizer(func, data, m_head);
6559
}
60+
6661
void pop() {
6762
auto n = m_head->m_next;
6863
delete m_head;
6964
m_head = n;
7065
}
7166

72-
7367
finalizer_array(finalizer_array&& other) noexcept: m_head(other.m_head) {
7468
other.m_head = MSGPACK_NULLPTR;
7569
}
70+
7671
finalizer_array& operator=(finalizer_array&& other) noexcept {
7772
m_head = other.m_head;
7873
other.m_head = MSGPACK_NULLPTR;
@@ -84,9 +79,11 @@ class zone {
8479
finalizer_array(const finalizer_array&);
8580
finalizer_array& operator=(const finalizer_array&);
8681
};
82+
8783
struct chunk {
8884
chunk* m_next;
8985
};
86+
9087
struct chunk_list {
9188
chunk_list(size_t chunk_size, char* ptr): m_free(chunk_size), m_ptr(ptr), m_head(MSGPACK_NULLPTR) {}
9289
~chunk_list() {
@@ -98,8 +95,8 @@ class zone {
9895
}
9996
m_head = MSGPACK_NULLPTR;
10097
}
101-
void clear(size_t chunk_size, char* ptr)
102-
{
98+
99+
void clear(size_t chunk_size, char* ptr) {
103100
chunk* c = m_head;
104101
while(c) {
105102
chunk* n = c->m_next;
@@ -114,12 +111,14 @@ class zone {
114111
size_t m_free;
115112
char* m_ptr;
116113
chunk* m_head;
114+
117115
private:
118116
chunk_list(chunk_list&& other) noexcept = delete;
119117
chunk_list& operator=(chunk_list&& other) noexcept = delete;
120118
chunk_list(const chunk_list&);
121119
chunk_list& operator=(const chunk_list&);
122120
};
121+
123122
size_t m_chunk_size;
124123
chunk_list* m_chunk_list{};
125124
finalizer_array m_finalizer_array;
@@ -141,23 +140,21 @@ class zone {
141140

142141
void swap(zone& o);
143142

144-
static void* operator new(std::size_t size)
145-
{
143+
static void* operator new(std::size_t size) {
146144
void* p = ::malloc(size);
147145
if (!p) throw std::bad_alloc();
148146
return p;
149147
}
150-
static void operator delete(void *p) noexcept
151-
{
148+
149+
static void operator delete(void *p) noexcept {
152150
::free(p);
153151
}
154-
static void* operator new(std::size_t /*size*/, void* mem) noexcept
155-
{
152+
153+
static void* operator new(std::size_t /*size*/, void* mem) noexcept {
156154
return mem;
157155
}
158-
static void operator delete(void * /*p*/, void* /*mem*/) noexcept
159-
{
160-
}
156+
157+
static void operator delete(void * /*p*/, void* /*mem*/) noexcept {}
161158

162159
template <typename T, typename... Args>
163160
T* allocate(Args... args);
@@ -183,12 +180,9 @@ class zone {
183180
char* allocate_expand(size_t size);
184181
};
185182

186-
inline zone::zone(size_t chunk_size):m_chunk_size(chunk_size), m_chunk_list(MSGPACK_NULLPTR)
187-
{
188-
}
183+
inline zone::zone(size_t chunk_size):m_chunk_size(chunk_size), m_chunk_list(MSGPACK_NULLPTR) {}
189184

190-
inline zone::~zone()
191-
{
185+
inline zone::~zone() {
192186
m_finalizer_array.~finalizer_array();
193187
if(m_chunk_list) {
194188
m_chunk_list->~chunk_list();
@@ -197,17 +191,15 @@ inline zone::~zone()
197191
}
198192
}
199193

200-
inline char* zone::get_aligned(char* ptr, size_t align)
201-
{
194+
inline char* zone::get_aligned(char* ptr, size_t align) {
202195
MSGPACK_ASSERT(align != 0 && (align & (align - 1)) == 0); // align must be 2^n (n >= 0)
203196
return
204197
reinterpret_cast<char*>(
205198
reinterpret_cast<uintptr_t>(ptr + (align - 1)) & ~static_cast<uintptr_t>(align - 1)
206199
);
207200
}
208201

209-
inline zone::chunk_list& zone::get_chank_lst()
210-
{
202+
inline zone::chunk_list& zone::get_chank_lst() {
211203
if (!m_chunk_list) {
212204
auto ptr = ::malloc(sizeof(chunk_list) + m_chunk_size);
213205
if (!ptr)
@@ -217,8 +209,7 @@ inline zone::chunk_list& zone::get_chank_lst()
217209
return *m_chunk_list;
218210
}
219211

220-
inline void* zone::allocate_align(size_t size, size_t align)
221-
{
212+
inline void* zone::allocate_align(size_t size, size_t align) {
222213
chunk_list& chank_lst = get_chank_lst();
223214
char* aligned = get_aligned(chank_lst.m_ptr, align);
224215
size_t adjusted_size = size + static_cast<size_t>(aligned - chank_lst.m_ptr);
@@ -245,8 +236,7 @@ inline void* zone::allocate_no_align(size_t size) {
245236
return ptr;
246237
}
247238

248-
inline char* zone::allocate_expand(size_t size)
249-
{
239+
inline char* zone::allocate_expand(size_t size) {
250240
chunk_list& cl = get_chank_lst();
251241
size_t sz = m_chunk_size;
252242

@@ -272,39 +262,33 @@ inline char* zone::allocate_expand(size_t size)
272262
return ptr;
273263
}
274264

275-
inline void zone::push_finalizer(void (*func)(void*), void* data)
276-
{
265+
inline void zone::push_finalizer(void (*func)(void*), void* data) {
277266
m_finalizer_array.push(func, data);
278267
}
279268

280269
template <typename T>
281-
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj)
282-
{
270+
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj) {
283271
m_finalizer_array.push(&zone::object_delete<T>, obj.release());
284272
}
285273

286-
inline void zone::clear()
287-
{
274+
inline void zone::clear() {
288275
m_finalizer_array.clear();
289276
if (m_chunk_list) {
290277
m_chunk_list->clear(m_chunk_size, reinterpret_cast<char*>(m_chunk_list) + sizeof(chunk_list));
291278
}
292279
}
293280

294-
inline void zone::swap(zone& o)
295-
{
281+
inline void zone::swap(zone& o) {
296282
std::swap(*this, o);
297283
}
298284

299285
template <typename T>
300-
void zone::object_delete(void* obj)
301-
{
286+
void zone::object_delete(void* obj) {
302287
delete static_cast<T*>(obj);
303288
}
304289

305290
template <typename T>
306-
void zone::object_destruct(void* obj)
307-
{
291+
void zone::object_destruct(void* obj) {
308292
static_cast<T*>(obj)->~T();
309293
}
310294

@@ -316,8 +300,7 @@ inline void zone::undo_allocate(size_t size) {
316300

317301

318302
template <typename T, typename... Args>
319-
T* zone::allocate(Args... args)
320-
{
303+
T* zone::allocate(Args... args) {
321304
void* x = allocate_align(sizeof(T), MSGPACK_ZONE_ALIGNOF(T));
322305
try {
323306
m_finalizer_array.push(&zone::object_destruct<T>, x);
@@ -334,9 +317,7 @@ T* zone::allocate(Args... args)
334317
}
335318
}
336319

337-
inline std::size_t aligned_size(
338-
std::size_t size,
339-
std::size_t align) {
320+
inline std::size_t aligned_size(std::size_t size, std::size_t align) {
340321
return (size + align - 1) / align * align;
341322
}
342323

0 commit comments

Comments
 (0)