Renamed member variables name.

This commit is contained in:
Takatoshi Kondo
2014-07-11 23:37:43 +09:00
parent 212f025f00
commit 0889e6117e
9 changed files with 4219 additions and 4219 deletions

View File

@@ -68,11 +68,11 @@ struct tuple_type<const T&> {
<%0.upto(i) {|j|%> <%0.upto(i) {|j|%>
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>> template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
struct tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>> : tuple_type<A<%=j%>> { struct tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>> : tuple_type<A<%=j%>> {
tuple_element(tuple<A0<%1.upto(i) {|k|%>, A<%=k%> <%}%>>& x) : _x(x.a<%=j%>) {} tuple_element(tuple<A0<%1.upto(i) {|k|%>, A<%=k%> <%}%>>& x) : m_x(x.a<%=j%>) {}
typename tuple_type<A<%=j%>>::reference get() { return _x; } typename tuple_type<A<%=j%>>::reference get() { return m_x; }
typename tuple_type<A<%=j%>>::const_reference get() const { return _x; } typename tuple_type<A<%=j%>>::const_reference get() const { return m_x; }
private: private:
typename tuple_type<A<%=j%>>::reference _x; typename tuple_type<A<%=j%>>::reference m_x;
}; };
<%}%> <%}%>
<%}%> <%}%>
@@ -81,10 +81,10 @@ private:
<%0.upto(i) {|j|%> <%0.upto(i) {|j|%>
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>> template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
struct const_tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>> : tuple_type<A<%=j%>> { struct const_tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>> : tuple_type<A<%=j%>> {
const_tuple_element(const tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>& x) : _x(x.a<%=j%>) {} const_tuple_element(const tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>& x) : m_x(x.a<%=j%>) {}
typename tuple_type<A<%=j%>>::const_reference get() const { return _x; } typename tuple_type<A<%=j%>>::const_reference get() const { return m_x; }
private: private:
typename tuple_type<A<%=j%>>::const_reference _x; typename tuple_type<A<%=j%>>::const_reference m_x;
}; };
<%}%> <%}%>
<%}%> <%}%>

View File

@@ -37,41 +37,41 @@ namespace msgpack {
class zone { class zone {
struct finalizer { struct finalizer {
finalizer(void (*func)(void*), void* data):func_(func), data_(data) {} finalizer(void (*func)(void*), void* data):m_func(func), m_data(data) {}
void operator()() { func_(data_); } void operator()() { m_func(m_data); }
void (*func_)(void*); void (*m_func)(void*);
void* data_; void* m_data;
}; };
struct finalizer_array { struct finalizer_array {
finalizer_array():tail_(nullptr), end_(nullptr), array_(nullptr) {} finalizer_array():m_tail(nullptr), m_end(nullptr), m_array(nullptr) {}
void call() { void call() {
finalizer* fin = tail_; finalizer* fin = m_tail;
for(; fin != array_; --fin) (*(fin-1))(); for(; fin != m_array; --fin) (*(fin-1))();
} }
~finalizer_array() { ~finalizer_array() {
call(); call();
::free(array_); ::free(m_array);
} }
void clear() { void clear() {
call(); call();
tail_ = array_; m_tail = m_array;
} }
void push(void (*func)(void* data), void* data) void push(void (*func)(void* data), void* data)
{ {
finalizer* fin = tail_; finalizer* fin = m_tail;
if(fin == end_) { if(fin == m_end) {
push_expand(func, data); push_expand(func, data);
return; return;
} }
fin->func_ = func; fin->m_func = func;
fin->data_ = data; fin->m_data = data;
++tail_; ++m_tail;
} }
void push_expand(void (*func)(void*), void* data) { void push_expand(void (*func)(void*), void* data) {
const size_t nused = end_ - array_; const size_t nused = m_end - m_array;
size_t nnext; size_t nnext;
if(nused == 0) { if(nused == 0) {
nnext = (sizeof(finalizer) < 72/2) ? nnext = (sizeof(finalizer) < 72/2) ?
@@ -80,23 +80,23 @@ class zone {
nnext = nused * 2; nnext = nused * 2;
} }
finalizer* tmp = finalizer* tmp =
static_cast<finalizer*>(::realloc(array_, sizeof(finalizer) * nnext)); static_cast<finalizer*>(::realloc(m_array, sizeof(finalizer) * nnext));
if(!tmp) { if(!tmp) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
array_ = tmp; m_array = tmp;
end_ = tmp + nnext; m_end = tmp + nnext;
tail_ = tmp + nused; m_tail = tmp + nused;
new (tail_) finalizer(func, data); new (m_tail) finalizer(func, data);
++tail_; ++m_tail;
} }
finalizer* tail_; finalizer* m_tail;
finalizer* end_; finalizer* m_end;
finalizer* array_; finalizer* m_array;
}; };
struct chunk { struct chunk {
chunk* next_; chunk* m_next;
}; };
struct chunk_list { struct chunk_list {
chunk_list(size_t chunk_size) chunk_list(size_t chunk_size)
@@ -106,16 +106,16 @@ class zone {
throw std::bad_alloc(); throw std::bad_alloc();
} }
head_ = c; m_head = c;
free_ = chunk_size; m_free = chunk_size;
ptr_ = reinterpret_cast<char*>(c) + sizeof(chunk); m_ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->next_ = nullptr; c->m_next = nullptr;
} }
~chunk_list() ~chunk_list()
{ {
chunk* c = head_; chunk* c = m_head;
while(true) { while(true) {
chunk* n = c->next_; chunk* n = c->m_next;
::free(c); ::free(c);
if(n) { if(n) {
c = n; c = n;
@@ -126,9 +126,9 @@ class zone {
} }
void clear(size_t chunk_size) void clear(size_t chunk_size)
{ {
chunk* c = head_; chunk* c = m_head;
while(true) { while(true) {
chunk* n = c->next_; chunk* n = c->m_next;
if(n) { if(n) {
::free(c); ::free(c);
c = n; c = n;
@@ -136,17 +136,17 @@ class zone {
break; break;
} }
} }
head_->next_ = nullptr; m_head->m_next = nullptr;
free_ = chunk_size; m_free = chunk_size;
ptr_ = reinterpret_cast<char*>(head_) + sizeof(chunk); m_ptr = reinterpret_cast<char*>(m_head) + sizeof(chunk);
} }
size_t free_; size_t m_free;
char* ptr_; char* m_ptr;
chunk* head_; chunk* m_head;
}; };
size_t chunk_size_; size_t m_chunk_size;
chunk_list chunk_list_; chunk_list m_chunk_list;
finalizer_array finalizer_array_; finalizer_array m_finalizer_array;
public: public:
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */; zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
@@ -214,7 +214,7 @@ inline void zone::destroy(zone* z)
::free(z); ::free(z);
} }
inline zone::zone(size_t chunk_size) /* throw() */ :chunk_size_(chunk_size), chunk_list_(chunk_size_) inline zone::zone(size_t chunk_size) /* throw() */ :m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
{ {
} }
@@ -226,22 +226,22 @@ inline void* zone::allocate_align(size_t size)
inline void* zone::allocate_no_align(size_t size) inline void* zone::allocate_no_align(size_t size)
{ {
if(chunk_list_.free_ < size) { if(m_chunk_list.m_free < size) {
return allocate_expand(size); return allocate_expand(size);
} }
char* ptr = chunk_list_.ptr_; char* ptr = m_chunk_list.m_ptr;
chunk_list_.free_ -= size; m_chunk_list.m_free -= size;
chunk_list_.ptr_ += size; m_chunk_list.m_ptr += size;
return ptr; return ptr;
} }
inline void* zone::allocate_expand(size_t size) inline void* zone::allocate_expand(size_t size)
{ {
chunk_list* const cl = &chunk_list_; chunk_list* const cl = &m_chunk_list;
size_t sz = chunk_size_; size_t sz = m_chunk_size;
while(sz < size) { while(sz < size) {
sz *= 2; sz *= 2;
@@ -251,30 +251,30 @@ inline void* zone::allocate_expand(size_t size)
char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk); char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->next_ = cl->head_; c->m_next = cl->m_head;
cl->head_ = c; cl->m_head = c;
cl->free_ = sz - size; cl->m_free = sz - size;
cl->ptr_ = ptr + size; cl->m_ptr = ptr + size;
return ptr; return ptr;
} }
inline void zone::push_finalizer(void (*func)(void*), void* data) inline void zone::push_finalizer(void (*func)(void*), void* data)
{ {
finalizer_array_.push(func, data); m_finalizer_array.push(func, data);
} }
template <typename T> template <typename T>
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj) inline void zone::push_finalizer(msgpack::unique_ptr<T> obj)
{ {
finalizer_array_.push(&zone::object_destructor<T>, obj.get()); m_finalizer_array.push(&zone::object_destructor<T>, obj.get());
obj.release(); obj.release();
} }
inline void zone::clear() inline void zone::clear()
{ {
finalizer_array_.clear(); m_finalizer_array.clear();
chunk_list_.clear(chunk_size_); m_chunk_list.clear(m_chunk_size);
} }
inline void zone::swap(zone& o) inline void zone::swap(zone& o)
@@ -290,8 +290,8 @@ void zone::object_destructor(void* obj)
inline void zone::undo_allocate(size_t size) inline void zone::undo_allocate(size_t size)
{ {
chunk_list_.ptr_ -= size; m_chunk_list.m_ptr -= size;
chunk_list_.free_ += size; m_chunk_list.m_free += size;
} }
<%0.upto(GENERATION_LIMIT) {|i|%> <%0.upto(GENERATION_LIMIT) {|i|%>
@@ -300,7 +300,7 @@ T* zone::allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -308,7 +308,7 @@ T* zone::allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>)
try { try {
return new (x) T(<%=(1..i).map{|j|"a#{j}"}.join(', ')%>); return new (x) T(<%=(1..i).map{|j|"a#{j}"}.join(', ')%>);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -37,41 +37,41 @@ namespace msgpack {
class zone { class zone {
struct finalizer { struct finalizer {
finalizer(void (*func)(void*), void* data):func_(func), data_(data) {} finalizer(void (*func)(void*), void* data):m_func(func), m_data(data) {}
void operator()() { func_(data_); } void operator()() { m_func(m_data); }
void (*func_)(void*); void (*m_func)(void*);
void* data_; void* m_data;
}; };
struct finalizer_array { struct finalizer_array {
finalizer_array():tail_(nullptr), end_(nullptr), array_(nullptr) {} finalizer_array():m_tail(nullptr), m_end(nullptr), m_array(nullptr) {}
void call() { void call() {
finalizer* fin = tail_; finalizer* fin = m_tail;
for(; fin != array_; --fin) (*(fin-1))(); for(; fin != m_array; --fin) (*(fin-1))();
} }
~finalizer_array() { ~finalizer_array() {
call(); call();
::free(array_); ::free(m_array);
} }
void clear() { void clear() {
call(); call();
tail_ = array_; m_tail = m_array;
} }
void push(void (*func)(void* data), void* data) void push(void (*func)(void* data), void* data)
{ {
finalizer* fin = tail_; finalizer* fin = m_tail;
if(fin == end_) { if(fin == m_end) {
push_expand(func, data); push_expand(func, data);
return; return;
} }
fin->func_ = func; fin->m_func = func;
fin->data_ = data; fin->m_data = data;
++tail_; ++m_tail;
} }
void push_expand(void (*func)(void*), void* data) { void push_expand(void (*func)(void*), void* data) {
const size_t nused = end_ - array_; const size_t nused = m_end - m_array;
size_t nnext; size_t nnext;
if(nused == 0) { if(nused == 0) {
nnext = (sizeof(finalizer) < 72/2) ? nnext = (sizeof(finalizer) < 72/2) ?
@@ -80,23 +80,23 @@ class zone {
nnext = nused * 2; nnext = nused * 2;
} }
finalizer* tmp = finalizer* tmp =
static_cast<finalizer*>(::realloc(array_, sizeof(finalizer) * nnext)); static_cast<finalizer*>(::realloc(m_array, sizeof(finalizer) * nnext));
if(!tmp) { if(!tmp) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
array_ = tmp; m_array = tmp;
end_ = tmp + nnext; m_end = tmp + nnext;
tail_ = tmp + nused; m_tail = tmp + nused;
new (tail_) finalizer(func, data); new (m_tail) finalizer(func, data);
++tail_; ++m_tail;
} }
finalizer* tail_; finalizer* m_tail;
finalizer* end_; finalizer* m_end;
finalizer* array_; finalizer* m_array;
}; };
struct chunk { struct chunk {
chunk* next_; chunk* m_next;
}; };
struct chunk_list { struct chunk_list {
chunk_list(size_t chunk_size) chunk_list(size_t chunk_size)
@@ -106,16 +106,16 @@ class zone {
throw std::bad_alloc(); throw std::bad_alloc();
} }
head_ = c; m_head = c;
free_ = chunk_size; m_free = chunk_size;
ptr_ = reinterpret_cast<char*>(c) + sizeof(chunk); m_ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->next_ = nullptr; c->m_next = nullptr;
} }
~chunk_list() ~chunk_list()
{ {
chunk* c = head_; chunk* c = m_head;
while(true) { while(true) {
chunk* n = c->next_; chunk* n = c->m_next;
::free(c); ::free(c);
if(n) { if(n) {
c = n; c = n;
@@ -126,9 +126,9 @@ class zone {
} }
void clear(size_t chunk_size) void clear(size_t chunk_size)
{ {
chunk* c = head_; chunk* c = m_head;
while(true) { while(true) {
chunk* n = c->next_; chunk* n = c->m_next;
if(n) { if(n) {
::free(c); ::free(c);
c = n; c = n;
@@ -136,17 +136,17 @@ class zone {
break; break;
} }
} }
head_->next_ = nullptr; m_head->m_next = nullptr;
free_ = chunk_size; m_free = chunk_size;
ptr_ = reinterpret_cast<char*>(head_) + sizeof(chunk); m_ptr = reinterpret_cast<char*>(m_head) + sizeof(chunk);
} }
size_t free_; size_t m_free;
char* ptr_; char* m_ptr;
chunk* head_; chunk* m_head;
}; };
size_t chunk_size_; size_t m_chunk_size;
chunk_list chunk_list_; chunk_list m_chunk_list;
finalizer_array finalizer_array_; finalizer_array m_finalizer_array;
public: public:
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */; zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
@@ -259,7 +259,7 @@ inline void zone::destroy(zone* z)
::free(z); ::free(z);
} }
inline zone::zone(size_t chunk_size) /* throw() */ :chunk_size_(chunk_size), chunk_list_(chunk_size_) inline zone::zone(size_t chunk_size) /* throw() */ :m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
{ {
} }
@@ -271,22 +271,22 @@ inline void* zone::allocate_align(size_t size)
inline void* zone::allocate_no_align(size_t size) inline void* zone::allocate_no_align(size_t size)
{ {
if(chunk_list_.free_ < size) { if(m_chunk_list.m_free < size) {
return allocate_expand(size); return allocate_expand(size);
} }
char* ptr = chunk_list_.ptr_; char* ptr = m_chunk_list.m_ptr;
chunk_list_.free_ -= size; m_chunk_list.m_free -= size;
chunk_list_.ptr_ += size; m_chunk_list.m_ptr += size;
return ptr; return ptr;
} }
inline void* zone::allocate_expand(size_t size) inline void* zone::allocate_expand(size_t size)
{ {
chunk_list* const cl = &chunk_list_; chunk_list* const cl = &m_chunk_list;
size_t sz = chunk_size_; size_t sz = m_chunk_size;
while(sz < size) { while(sz < size) {
sz *= 2; sz *= 2;
@@ -296,30 +296,30 @@ inline void* zone::allocate_expand(size_t size)
char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk); char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->next_ = cl->head_; c->m_next = cl->m_head;
cl->head_ = c; cl->m_head = c;
cl->free_ = sz - size; cl->m_free = sz - size;
cl->ptr_ = ptr + size; cl->m_ptr = ptr + size;
return ptr; return ptr;
} }
inline void zone::push_finalizer(void (*func)(void*), void* data) inline void zone::push_finalizer(void (*func)(void*), void* data)
{ {
finalizer_array_.push(func, data); m_finalizer_array.push(func, data);
} }
template <typename T> template <typename T>
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj) inline void zone::push_finalizer(msgpack::unique_ptr<T> obj)
{ {
finalizer_array_.push(&zone::object_destructor<T>, obj.get()); m_finalizer_array.push(&zone::object_destructor<T>, obj.get());
obj.release(); obj.release();
} }
inline void zone::clear() inline void zone::clear()
{ {
finalizer_array_.clear(); m_finalizer_array.clear();
chunk_list_.clear(chunk_size_); m_chunk_list.clear(m_chunk_size);
} }
inline void zone::swap(zone& o) inline void zone::swap(zone& o)
@@ -335,8 +335,8 @@ void zone::object_destructor(void* obj)
inline void zone::undo_allocate(size_t size) inline void zone::undo_allocate(size_t size)
{ {
chunk_list_.ptr_ -= size; m_chunk_list.m_ptr -= size;
chunk_list_.free_ += size; m_chunk_list.m_free += size;
} }
@@ -345,7 +345,7 @@ T* zone::allocate()
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -353,7 +353,7 @@ T* zone::allocate()
try { try {
return new (x) T(); return new (x) T();
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -364,7 +364,7 @@ T* zone::allocate(A1 a1)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -372,7 +372,7 @@ T* zone::allocate(A1 a1)
try { try {
return new (x) T(a1); return new (x) T(a1);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -383,7 +383,7 @@ T* zone::allocate(A1 a1, A2 a2)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -391,7 +391,7 @@ T* zone::allocate(A1 a1, A2 a2)
try { try {
return new (x) T(a1, a2); return new (x) T(a1, a2);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -402,7 +402,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -410,7 +410,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3)
try { try {
return new (x) T(a1, a2, a3); return new (x) T(a1, a2, a3);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -421,7 +421,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -429,7 +429,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4)
try { try {
return new (x) T(a1, a2, a3, a4); return new (x) T(a1, a2, a3, a4);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -440,7 +440,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -448,7 +448,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
try { try {
return new (x) T(a1, a2, a3, a4, a5); return new (x) T(a1, a2, a3, a4, a5);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -459,7 +459,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -467,7 +467,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6); return new (x) T(a1, a2, a3, a4, a5, a6);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -478,7 +478,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -486,7 +486,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7); return new (x) T(a1, a2, a3, a4, a5, a6, a7);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -497,7 +497,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -505,7 +505,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8); return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -516,7 +516,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -524,7 +524,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9); return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -535,7 +535,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -543,7 +543,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -554,7 +554,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -562,7 +562,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -573,7 +573,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -581,7 +581,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -592,7 +592,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -600,7 +600,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -611,7 +611,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -619,7 +619,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }
@@ -630,7 +630,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -638,7 +638,7 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
try { try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }

View File

@@ -37,41 +37,41 @@ namespace msgpack {
class zone { class zone {
private: private:
struct finalizer { struct finalizer {
finalizer(void (*func)(void*), void* data):func_(func), data_(data) {} finalizer(void (*func)(void*), void* data):m_func(func), m_data(data) {}
void operator()() { func_(data_); } void operator()() { m_func(m_data); }
void (*func_)(void*); void (*m_func)(void*);
void* data_; void* m_data;
}; };
struct finalizer_array { struct finalizer_array {
finalizer_array():tail_(nullptr), end_(nullptr), array_(nullptr) {} finalizer_array():m_tail(nullptr), m_end(nullptr), m_array(nullptr) {}
void call() { void call() {
finalizer* fin = tail_; finalizer* fin = m_tail;
for(; fin != array_; --fin) (*(fin-1))(); for(; fin != m_array; --fin) (*(fin-1))();
} }
~finalizer_array() { ~finalizer_array() {
call(); call();
::free(array_); ::free(m_array);
} }
void clear() { void clear() {
call(); call();
tail_ = array_; m_tail = m_array;
} }
void push(void (*func)(void* data), void* data) void push(void (*func)(void* data), void* data)
{ {
finalizer* fin = tail_; finalizer* fin = m_tail;
if(fin == end_) { if(fin == m_end) {
push_expand(func, data); push_expand(func, data);
return; return;
} }
fin->func_ = func; fin->m_func = func;
fin->data_ = data; fin->m_data = data;
++tail_; ++m_tail;
} }
void push_expand(void (*func)(void*), void* data) { void push_expand(void (*func)(void*), void* data) {
const size_t nused = end_ - array_; const size_t nused = m_end - m_array;
size_t nnext; size_t nnext;
if(nused == 0) { if(nused == 0) {
nnext = (sizeof(finalizer) < 72/2) ? nnext = (sizeof(finalizer) < 72/2) ?
@@ -80,23 +80,23 @@ private:
nnext = nused * 2; nnext = nused * 2;
} }
finalizer* tmp = finalizer* tmp =
static_cast<finalizer*>(::realloc(array_, sizeof(finalizer) * nnext)); static_cast<finalizer*>(::realloc(m_array, sizeof(finalizer) * nnext));
if(!tmp) { if(!tmp) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
array_ = tmp; m_array = tmp;
end_ = tmp + nnext; m_end = tmp + nnext;
tail_ = tmp + nused; m_tail = tmp + nused;
new (tail_) finalizer(func, data); new (m_tail) finalizer(func, data);
++tail_; ++m_tail;
} }
finalizer* tail_; finalizer* m_tail;
finalizer* end_; finalizer* m_end;
finalizer* array_; finalizer* m_array;
}; };
struct chunk { struct chunk {
chunk* next_; chunk* m_next;
}; };
struct chunk_list { struct chunk_list {
chunk_list(size_t chunk_size) chunk_list(size_t chunk_size)
@@ -106,16 +106,16 @@ private:
throw std::bad_alloc(); throw std::bad_alloc();
} }
head_ = c; m_head = c;
free_ = chunk_size; m_free = chunk_size;
ptr_ = reinterpret_cast<char*>(c) + sizeof(chunk); m_ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->next_ = nullptr; c->m_next = nullptr;
} }
~chunk_list() ~chunk_list()
{ {
chunk* c = head_; chunk* c = m_head;
while(true) { while(true) {
chunk* n = c->next_; chunk* n = c->m_next;
::free(c); ::free(c);
if(n) { if(n) {
c = n; c = n;
@@ -126,28 +126,28 @@ private:
} }
void clear(size_t chunk_size) void clear(size_t chunk_size)
{ {
chunk* c = head_; chunk* c = m_head;
while(true) { while(true) {
chunk* n = c->next_; chunk* n = c->m_next;
if(n) { if(n) {
::free(c); ::free(c);
c = n; c = n;
} else { } else {
head_ = c; m_head = c;
break; break;
} }
} }
head_->next_ = nullptr; m_head->m_next = nullptr;
free_ = chunk_size; m_free = chunk_size;
ptr_ = reinterpret_cast<char*>(head_) + sizeof(chunk); m_ptr = reinterpret_cast<char*>(m_head) + sizeof(chunk);
} }
size_t free_; size_t m_free;
char* ptr_; char* m_ptr;
chunk* head_; chunk* m_head;
}; };
size_t chunk_size_; size_t m_chunk_size;
chunk_list chunk_list_; chunk_list m_chunk_list;
finalizer_array finalizer_array_; finalizer_array m_finalizer_array;
public: public:
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) noexcept; zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) noexcept;
@@ -214,7 +214,7 @@ inline void zone::destroy(zone* z)
::free(z); ::free(z);
} }
inline zone::zone(size_t chunk_size) noexcept:chunk_size_(chunk_size), chunk_list_(chunk_size_) inline zone::zone(size_t chunk_size) noexcept:m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
{ {
} }
@@ -226,22 +226,22 @@ inline void* zone::allocate_align(size_t size)
inline void* zone::allocate_no_align(size_t size) inline void* zone::allocate_no_align(size_t size)
{ {
if(chunk_list_.free_ < size) { if(m_chunk_list.m_free < size) {
return allocate_expand(size); return allocate_expand(size);
} }
char* ptr = chunk_list_.ptr_; char* ptr = m_chunk_list.m_ptr;
chunk_list_.free_ -= size; m_chunk_list.m_free -= size;
chunk_list_.ptr_ += size; m_chunk_list.m_ptr += size;
return ptr; return ptr;
} }
inline void* zone::allocate_expand(size_t size) inline void* zone::allocate_expand(size_t size)
{ {
chunk_list* const cl = &chunk_list_; chunk_list* const cl = &m_chunk_list;
size_t sz = chunk_size_; size_t sz = m_chunk_size;
while(sz < size) { while(sz < size) {
sz *= 2; sz *= 2;
@@ -252,30 +252,30 @@ inline void* zone::allocate_expand(size_t size)
char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk); char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->next_ = cl->head_; c->m_next = cl->m_head;
cl->head_ = c; cl->m_head = c;
cl->free_ = sz - size; cl->m_free = sz - size;
cl->ptr_ = ptr + size; cl->m_ptr = ptr + size;
return ptr; return ptr;
} }
inline void zone::push_finalizer(void (*func)(void*), void* data) inline void zone::push_finalizer(void (*func)(void*), void* data)
{ {
finalizer_array_.push(func, data); m_finalizer_array.push(func, data);
} }
template <typename T> template <typename T>
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj) inline void zone::push_finalizer(msgpack::unique_ptr<T> obj)
{ {
finalizer_array_.push(&zone::object_destructor<T>, obj.get()); m_finalizer_array.push(&zone::object_destructor<T>, obj.get());
obj.release(); obj.release();
} }
inline void zone::clear() inline void zone::clear()
{ {
finalizer_array_.clear(); m_finalizer_array.clear();
chunk_list_.clear(chunk_size_); m_chunk_list.clear(m_chunk_size);
} }
inline void zone::swap(zone& o) inline void zone::swap(zone& o)
@@ -291,8 +291,8 @@ void zone::object_destructor(void* obj)
inline void zone::undo_allocate(size_t size) inline void zone::undo_allocate(size_t size)
{ {
chunk_list_.ptr_ -= size; m_chunk_list.m_ptr -= size;
chunk_list_.free_ += size; m_chunk_list.m_free += size;
} }
@@ -301,7 +301,7 @@ T* zone::allocate(Args... args)
{ {
void* x = allocate_align(sizeof(T)); void* x = allocate_align(sizeof(T));
try { try {
finalizer_array_.push(&zone::object_destructor<T>, x); m_finalizer_array.push(&zone::object_destructor<T>, x);
} catch (...) { } catch (...) {
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
@@ -309,7 +309,7 @@ T* zone::allocate(Args... args)
try { try {
return new (x) T(args...); return new (x) T(args...);
} catch (...) { } catch (...) {
--finalizer_array_.tail_; --m_finalizer_array.m_tail;
undo_allocate(sizeof(T)); undo_allocate(sizeof(T));
throw; throw;
} }

View File

@@ -29,13 +29,13 @@ namespace msgpack {
class sbuffer { class sbuffer {
public: public:
sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE):size_(0), alloc_(initsz) sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE):m_size(0), m_alloc(initsz)
{ {
if(initsz == 0) { if(initsz == 0) {
data_ = nullptr; m_data = nullptr;
} else { } else {
data_ = (char*)::malloc(initsz); m_data = (char*)::malloc(initsz);
if(!data_) { if(!m_data) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
} }
@@ -43,71 +43,71 @@ public:
~sbuffer() ~sbuffer()
{ {
::free(data_); ::free(m_data);
} }
public: public:
void write(const char* buf, size_t len) void write(const char* buf, size_t len)
{ {
if(alloc_ - size_ < len) { if(m_alloc - m_size < len) {
expand_buffer(len); expand_buffer(len);
} }
::memcpy(data_ + size_, buf, len); ::memcpy(m_data + m_size, buf, len);
size_ += len; m_size += len;
} }
char* data() char* data()
{ {
return data_; return m_data;
} }
const char* data() const const char* data() const
{ {
return data_; return m_data;
} }
size_t size() const size_t size() const
{ {
return size_; return m_size;
} }
char* release() char* release()
{ {
char* tmp = data_; char* tmp = m_data;
size_ = 0; m_size = 0;
data_ = nullptr; m_data = nullptr;
alloc_ = 0; m_alloc = 0;
return tmp; return tmp;
} }
void clear() void clear()
{ {
size_ = 0; m_size = 0;
} }
private: private:
void expand_buffer(size_t len) void expand_buffer(size_t len)
{ {
size_t nsize = (alloc_ > 0) ? size_t nsize = (m_alloc > 0) ?
alloc_ * 2 : MSGPACK_SBUFFER_INIT_SIZE; m_alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
while(nsize < size_ + len) { nsize *= 2; } while(nsize < m_size + len) { nsize *= 2; }
void* tmp = ::realloc(data_, nsize); void* tmp = ::realloc(m_data, nsize);
if(!tmp) { if(!tmp) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
data_ = static_cast<char*>(tmp); m_data = static_cast<char*>(tmp);
alloc_ = nsize; m_alloc = nsize;
} }
private: private:
sbuffer(const sbuffer&); sbuffer(const sbuffer&);
private: private:
size_t size_; size_t m_size;
char* data_; char* m_data;
size_t alloc_; size_t m_alloc;
}; };

View File

@@ -52,14 +52,14 @@ namespace detail {
class unpack_user { class unpack_user {
public: public:
msgpack::zone const& zone() const { return *zone_; } msgpack::zone const& zone() const { return *m_zone; }
msgpack::zone& zone() { return *zone_; } msgpack::zone& zone() { return *m_zone; }
void set_zone(msgpack::zone& zone) { zone_ = &zone; } void set_zone(msgpack::zone& zone) { m_zone = &zone; }
bool referenced() const { return referenced_; } bool referenced() const { return m_referenced; }
void set_referenced(bool referenced) { referenced_ = referenced; } void set_referenced(bool referenced) { m_referenced = referenced; }
private: private:
msgpack::zone* zone_; msgpack::zone* m_zone;
bool referenced_; bool m_referenced;
}; };
inline void unpack_uint8(uint8_t d, object& o) inline void unpack_uint8(uint8_t d, object& o)
@@ -165,21 +165,21 @@ inline void unpack_bin(unpack_user& u, const char* b, const char* p, unsigned in
class unpack_stack { class unpack_stack {
public: public:
object const& obj() const { return obj_; } object const& obj() const { return m_obj; }
object& obj() { return obj_; } object& obj() { return m_obj; }
void set_obj(object const& obj) { obj_ = obj; } void set_obj(object const& obj) { m_obj = obj; }
size_t count() const { return count_; } size_t count() const { return m_count; }
void set_count(size_t count) { count_ = count; } void set_count(size_t count) { m_count = count; }
size_t decl_count() { return --count_; } size_t decl_count() { return --m_count; }
unsigned int container_type() const { return container_type_; } unsigned int container_type() const { return m_container_type; }
void set_container_type(unsigned int container_type) { container_type_ = container_type; } void set_container_type(unsigned int container_type) { m_container_type = container_type; }
object const& map_key() const { return map_key_; } object const& map_key() const { return m_map_key; }
void set_map_key(object const& map_key) { map_key_ = map_key; } void set_map_key(object const& map_key) { m_map_key = map_key; }
private: private:
object obj_; object m_obj;
size_t count_; size_t m_count;
unsigned int container_type_; unsigned int m_container_type;
object map_key_; object m_map_key;
}; };
inline void init_count(void* buffer) inline void init_count(void* buffer)
@@ -244,62 +244,62 @@ inline void load(T& dst, const char* n, typename msgpack::enable_if<sizeof(T) ==
class context { class context {
public: public:
context():trail_(0), cs_(CS_HEADER), top_(0) context():m_trail(0), m_cs(CS_HEADER), m_top(0)
{ {
stack_[0].set_obj(object()); m_stack[0].set_obj(object());
} }
void init() void init()
{ {
cs_ = CS_HEADER; m_cs = CS_HEADER;
trail_ = 0; m_trail = 0;
top_ = 0; m_top = 0;
stack_[0].set_obj(object()); m_stack[0].set_obj(object());
} }
object const& data() const object const& data() const
{ {
return stack_[0].obj(); return m_stack[0].obj();
} }
unpack_user& user() unpack_user& user()
{ {
return user_; return m_user;
} }
unpack_user const& user() const unpack_user const& user() const
{ {
return user_; return m_user;
} }
int execute(const char* data, size_t len, size_t& off) int execute(const char* data, size_t len, size_t& off)
{ {
assert(len >= off); assert(len >= off);
start_ = data; m_start = data;
current_ = data + off; m_current = data + off;
stack_idx_ = 0; m_stack_idx = 0;
const char* const pe = data + len; const char* const pe = data + len;
const char* n = nullptr; const char* n = nullptr;
object obj; object obj;
if(current_ == pe) { if(m_current == pe) {
off = current_ - start_; off = m_current - m_start;
return 0; return 0;
} }
bool fixed_trail_again = false; bool fixed_trail_again = false;
do { do {
if (cs_ == CS_HEADER) { if (m_cs == CS_HEADER) {
fixed_trail_again = false; fixed_trail_again = false;
int selector = *reinterpret_cast<const unsigned char*>(current_); int selector = *reinterpret_cast<const unsigned char*>(m_current);
if (0) { if (0) {
} else if(0x00 <= selector && selector <= 0x7f) { // Positive Fixnum } else if(0x00 <= selector && selector <= 0x7f) { // Positive Fixnum
unpack_uint8(*reinterpret_cast<const uint8_t*>(current_), obj); unpack_uint8(*reinterpret_cast<const uint8_t*>(m_current), obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} else if(0xe0 <= selector && selector <= 0xff) { // Negative Fixnum } else if(0xe0 <= selector && selector <= 0xff) { // Negative Fixnum
unpack_int8(*reinterpret_cast<const int8_t*>(current_), obj); unpack_int8(*reinterpret_cast<const int8_t*>(m_current), obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} else if(0xc0 <= selector && selector <= 0xdf) { // Variable } else if(0xc0 <= selector && selector <= 0xdf) { // Variable
@@ -323,8 +323,8 @@ public:
case 0xc4: // bin 8 case 0xc4: // bin 8
case 0xc5: // bin 16 case 0xc5: // bin 16
case 0xc6: // bin 32 case 0xc6: // bin 32
trail_ = 1 << (static_cast<unsigned int>(*current_) & 0x03); m_trail = 1 << (static_cast<unsigned int>(*m_current) & 0x03);
cs_ = next_cs(current_); m_cs = next_cs(m_current);
fixed_trail_again = true; fixed_trail_again = true;
break; break;
@@ -341,8 +341,8 @@ public:
case 0xd1: // signed int 16 case 0xd1: // signed int 16
case 0xd2: // signed int 32 case 0xd2: // signed int 32
case 0xd3: // signed int 64 case 0xd3: // signed int 64
trail_ = 1 << (static_cast<unsigned int>(*current_) & 0x03); m_trail = 1 << (static_cast<unsigned int>(*m_current) & 0x03);
cs_ = next_cs(current_); m_cs = next_cs(m_current);
fixed_trail_again = true; fixed_trail_again = true;
break; break;
//case 0xd4: //case 0xd4:
@@ -353,60 +353,60 @@ public:
case 0xd9: // str 8 case 0xd9: // str 8
case 0xda: // str 16 case 0xda: // str 16
case 0xdb: // str 32 case 0xdb: // str 32
trail_ = 1 << ((static_cast<unsigned int>(*current_) & 0x03) - 1); m_trail = 1 << ((static_cast<unsigned int>(*m_current) & 0x03) - 1);
cs_ = next_cs(current_); m_cs = next_cs(m_current);
fixed_trail_again = true; fixed_trail_again = true;
break; break;
case 0xdc: // array 16 case 0xdc: // array 16
case 0xdd: // array 32 case 0xdd: // array 32
case 0xde: // map 16 case 0xde: // map 16
case 0xdf: // map 32 case 0xdf: // map 32
trail_ = 2 << (static_cast<unsigned int>(*current_) & 0x01); m_trail = 2 << (static_cast<unsigned int>(*m_current) & 0x01);
cs_ = next_cs(current_); m_cs = next_cs(m_current);
fixed_trail_again = true; fixed_trail_again = true;
break; break;
default: default:
off = current_ - start_; off = m_current - m_start;
return -1; return -1;
} }
} else if(0xa0 <= selector && selector <= 0xbf) { // FixStr } else if(0xa0 <= selector && selector <= 0xbf) { // FixStr
trail_ = static_cast<unsigned int>(*current_) & 0x1f; m_trail = static_cast<unsigned int>(*m_current) & 0x1f;
if(trail_ == 0) { if(m_trail == 0) {
unpack_str(user_, data, n, trail_, obj); unpack_str(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} }
else { else {
cs_ = ACS_STR_VALUE; m_cs = ACS_STR_VALUE;
fixed_trail_again = true; fixed_trail_again = true;
} }
} else if(0x90 <= selector && selector <= 0x9f) { // FixArray } else if(0x90 <= selector && selector <= 0x9f) { // FixArray
int ret = push_aggregate<fix_tag>( int ret = push_aggregate<fix_tag>(
unpack_array(), CT_ARRAY_ITEM, obj, current_, off); unpack_array(), CT_ARRAY_ITEM, obj, m_current, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} else if(0x80 <= selector && selector <= 0x8f) { // FixMap } else if(0x80 <= selector && selector <= 0x8f) { // FixMap
int ret = push_aggregate<fix_tag>( int ret = push_aggregate<fix_tag>(
unpack_map(), CT_MAP_KEY, obj, current_, off); unpack_map(), CT_MAP_KEY, obj, m_current, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} else { } else {
off = current_ - start_; off = m_current - m_start;
return -1; return -1;
} }
// end CS_HEADER // end CS_HEADER
} }
if (cs_ != CS_HEADER || fixed_trail_again) { if (m_cs != CS_HEADER || fixed_trail_again) {
if (fixed_trail_again) { if (fixed_trail_again) {
++current_; ++m_current;
fixed_trail_again = false; fixed_trail_again = false;
} }
if((size_t)(pe - current_) < trail_) { if((size_t)(pe - m_current) < m_trail) {
off = current_ - start_; off = m_current - m_start;
return 0; return 0;
} }
n = current_; n = m_current;
current_ += trail_ - 1; m_current += m_trail - 1;
switch(cs_) { switch(m_cs) {
//case CS_ //case CS_
//case CS_ //case CS_
case CS_FLOAT: { case CS_FLOAT: {
@@ -486,90 +486,90 @@ public:
case CS_STR_8: { case CS_STR_8: {
uint8_t tmp; uint8_t tmp;
load<uint8_t>(tmp, n); load<uint8_t>(tmp, n);
trail_ = tmp; m_trail = tmp;
if(trail_ == 0) { if(m_trail == 0) {
unpack_str(user_, data, n, trail_, obj); unpack_str(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} }
else { else {
cs_ = ACS_STR_VALUE; m_cs = ACS_STR_VALUE;
fixed_trail_again = true; fixed_trail_again = true;
} }
} break; } break;
case CS_BIN_8: { case CS_BIN_8: {
uint8_t tmp; uint8_t tmp;
load<uint8_t>(tmp, n); load<uint8_t>(tmp, n);
trail_ = tmp; m_trail = tmp;
if(trail_ == 0) { if(m_trail == 0) {
unpack_bin(user_, data, n, trail_, obj); unpack_bin(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} }
else { else {
cs_ = ACS_BIN_VALUE; m_cs = ACS_BIN_VALUE;
fixed_trail_again = true; fixed_trail_again = true;
} }
} break; } break;
case CS_STR_16: { case CS_STR_16: {
uint16_t tmp; uint16_t tmp;
load<uint16_t>(tmp, n); load<uint16_t>(tmp, n);
trail_ = tmp; m_trail = tmp;
if(trail_ == 0) { if(m_trail == 0) {
unpack_str(user_, data, n, trail_, obj); unpack_str(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} }
else { else {
cs_ = ACS_STR_VALUE; m_cs = ACS_STR_VALUE;
fixed_trail_again = true; fixed_trail_again = true;
} }
} break; } break;
case CS_BIN_16: { case CS_BIN_16: {
uint16_t tmp; uint16_t tmp;
load<uint16_t>(tmp, n); load<uint16_t>(tmp, n);
trail_ = tmp; m_trail = tmp;
if(trail_ == 0) { if(m_trail == 0) {
unpack_bin(user_, data, n, trail_, obj); unpack_bin(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} }
else { else {
cs_ = ACS_BIN_VALUE; m_cs = ACS_BIN_VALUE;
fixed_trail_again = true; fixed_trail_again = true;
} }
} break; } break;
case CS_STR_32: case CS_STR_32:
load<uint32_t>(trail_, n); load<uint32_t>(m_trail, n);
if(trail_ == 0) { if(m_trail == 0) {
unpack_str(user_, data, n, trail_, obj); unpack_str(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} }
else { else {
cs_ = ACS_STR_VALUE; m_cs = ACS_STR_VALUE;
fixed_trail_again = true; fixed_trail_again = true;
} }
break; break;
case CS_BIN_32: case CS_BIN_32:
load<uint32_t>(trail_, n); load<uint32_t>(m_trail, n);
if(trail_ == 0) { if(m_trail == 0) {
unpack_bin(user_, data, n, trail_, obj); unpack_bin(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} }
else { else {
cs_ = ACS_BIN_VALUE; m_cs = ACS_BIN_VALUE;
fixed_trail_again = true; fixed_trail_again = true;
} }
break; break;
case ACS_STR_VALUE: { case ACS_STR_VALUE: {
unpack_str(user_, data, n, trail_, obj); unpack_str(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} break; } break;
case ACS_BIN_VALUE: { case ACS_BIN_VALUE: {
unpack_bin(user_, data, n, trail_, obj); unpack_bin(m_user, data, n, m_trail, obj);
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} break; } break;
@@ -596,13 +596,13 @@ public:
if (ret != 0) return ret; if (ret != 0) return ret;
} break; } break;
default: default:
off = current_ - start_; off = m_current - m_start;
return -1; return -1;
} }
} }
} while(current_ != pe); } while(m_current != pe);
off = current_ - start_; off = m_current - m_start;
return 0; return 0;
} }
@@ -620,30 +620,30 @@ private:
object& obj, object& obj,
const char* load_pos, const char* load_pos,
size_t& off) { size_t& off) {
if(top_ < MSGPACK_EMBED_STACK_SIZE /* FIXME */) { if(m_top < MSGPACK_EMBED_STACK_SIZE /* FIXME */) {
typename value<T>::type tmp; typename value<T>::type tmp;
load<T>(tmp, load_pos); load<T>(tmp, load_pos);
if (f(user_, tmp, stack_[top_].obj())) { if (f(m_user, tmp, m_stack[m_top].obj())) {
if(tmp == 0) { if(tmp == 0) {
obj = stack_[top_].obj(); obj = m_stack[m_top].obj();
int ret = push_proc(obj, off); int ret = push_proc(obj, off);
if (ret != 0) return ret; if (ret != 0) return ret;
} }
else { else {
stack_[top_].set_container_type(container_type); m_stack[m_top].set_container_type(container_type);
stack_[top_].set_count(tmp); m_stack[m_top].set_count(tmp);
++top_; ++m_top;
cs_ = CS_HEADER; m_cs = CS_HEADER;
++current_; ++m_current;
} }
} }
else { else {
off = current_ - start_; off = m_current - m_start;
return -1; return -1;
} }
} }
else { else {
off = current_ - start_; off = m_current - m_start;
return -1; return -1;
} }
return 0; return 0;
@@ -652,18 +652,18 @@ private:
int push_item(object& obj) { int push_item(object& obj) {
bool finish = false; bool finish = false;
while (!finish) { while (!finish) {
if(top_ == 0) { if(m_top == 0) {
return 1; return 1;
} }
stack_idx_ = top_ - 1; m_stack_idx = m_top - 1;
unpack_stack* sp = &stack_[stack_idx_]; unpack_stack* sp = &m_stack[m_stack_idx];
switch(sp->container_type()) { switch(sp->container_type()) {
case CT_ARRAY_ITEM: case CT_ARRAY_ITEM:
unpack_array_item(sp->obj(), obj); unpack_array_item(sp->obj(), obj);
if(sp->decl_count() == 0) { if(sp->decl_count() == 0) {
obj = sp->obj(); obj = sp->obj();
--top_; --m_top;
/*printf("stack pop %d\n", top_);*/ /*printf("stack pop %d\n", m_top);*/
} }
else { else {
finish = true; finish = true;
@@ -678,8 +678,8 @@ private:
unpack_map_item(sp->obj(), sp->map_key(), obj); unpack_map_item(sp->obj(), sp->map_key(), obj);
if(sp->decl_count() == 0) { if(sp->decl_count() == 0) {
obj = sp->obj(); obj = sp->obj();
--top_; --m_top;
/*printf("stack pop %d\n", top_);*/ /*printf("stack pop %d\n", m_top);*/
} }
else { else {
sp->set_container_type(CT_MAP_KEY); sp->set_container_type(CT_MAP_KEY);
@@ -696,31 +696,31 @@ private:
int push_proc(object& obj, size_t& off) { int push_proc(object& obj, size_t& off) {
int ret = push_item(obj); int ret = push_item(obj);
if (ret > 0) { if (ret > 0) {
stack_[0].set_obj(obj); m_stack[0].set_obj(obj);
++current_; ++m_current;
/*printf("-- finish --\n"); */ /*printf("-- finish --\n"); */
off = current_ - start_; off = m_current - m_start;
} }
else if (ret < 0) { else if (ret < 0) {
off = current_ - start_; off = m_current - m_start;
} }
else { else {
cs_ = CS_HEADER; m_cs = CS_HEADER;
++current_; ++m_current;
} }
return ret; return ret;
} }
private: private:
char const* start_; char const* m_start;
char const* current_; char const* m_current;
unsigned int trail_; unsigned int m_trail;
unpack_user user_; unpack_user m_user;
unsigned int cs_; unsigned int m_cs;
unsigned int top_; unsigned int m_top;
unsigned int stack_idx_; unsigned int m_stack_idx;
unpack_stack stack_[MSGPACK_EMBED_STACK_SIZE]; unpack_stack m_stack[MSGPACK_EMBED_STACK_SIZE];
}; };
} // detail } // detail
@@ -853,14 +853,14 @@ private:
bool flush_zone(); bool flush_zone();
private: private:
char* buffer_; char* m_buffer;
size_t used_; size_t m_used;
size_t free_; size_t m_free;
size_t off_; size_t m_off;
size_t parsed_; size_t m_parsed;
zone* z_; zone* m_z;
size_t initial_buffer_size_; size_t m_initial_buffer_size;
detail::context ctx_; detail::context m_ctx;
private: private:
unpacker(const unpacker&); unpacker(const unpacker&);
@@ -909,63 +909,63 @@ inline unpacker::unpacker(size_t initial_buffer_size)
throw std::bad_alloc(); throw std::bad_alloc();
} }
buffer_ = buffer; m_buffer = buffer;
used_ = COUNTER_SIZE; m_used = COUNTER_SIZE;
free_ = initial_buffer_size - used_; m_free = initial_buffer_size - m_used;
off_ = COUNTER_SIZE; m_off = COUNTER_SIZE;
parsed_ = 0; m_parsed = 0;
initial_buffer_size_ = initial_buffer_size; m_initial_buffer_size = initial_buffer_size;
z_ = z; m_z = z;
detail::init_count(buffer_); detail::init_count(m_buffer);
ctx_.init(); m_ctx.init();
ctx_.user().set_zone(*z_); m_ctx.user().set_zone(*m_z);
ctx_.user().set_referenced(false); m_ctx.user().set_referenced(false);
} }
inline unpacker::~unpacker() inline unpacker::~unpacker()
{ {
zone::destroy(z_); zone::destroy(m_z);
detail::decl_count(buffer_); detail::decl_count(m_buffer);
} }
inline void unpacker::reserve_buffer(size_t size) inline void unpacker::reserve_buffer(size_t size)
{ {
if(free_ >= size) return; if(m_free >= size) return;
expand_buffer(size); expand_buffer(size);
} }
inline void unpacker::expand_buffer(size_t size) inline void unpacker::expand_buffer(size_t size)
{ {
if(used_ == off_ && detail::get_count(buffer_) == 1 if(m_used == m_off && detail::get_count(m_buffer) == 1
&& !ctx_.user().referenced()) { && !m_ctx.user().referenced()) {
// rewind buffer // rewind buffer
free_ += used_ - COUNTER_SIZE; m_free += m_used - COUNTER_SIZE;
used_ = COUNTER_SIZE; m_used = COUNTER_SIZE;
off_ = COUNTER_SIZE; m_off = COUNTER_SIZE;
if(free_ >= size) return; if(m_free >= size) return;
} }
if(off_ == COUNTER_SIZE) { if(m_off == COUNTER_SIZE) {
size_t next_size = (used_ + free_) * 2; // include COUNTER_SIZE size_t next_size = (m_used + m_free) * 2; // include COUNTER_SIZE
while(next_size < size + used_) { while(next_size < size + m_used) {
next_size *= 2; next_size *= 2;
} }
char* tmp = static_cast<char*>(::realloc(buffer_, next_size)); char* tmp = static_cast<char*>(::realloc(m_buffer, next_size));
if(!tmp) { if(!tmp) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
buffer_ = tmp; m_buffer = tmp;
free_ = next_size - used_; m_free = next_size - m_used;
} else { } else {
size_t next_size = initial_buffer_size_; // include COUNTER_SIZE size_t next_size = m_initial_buffer_size; // include COUNTER_SIZE
size_t not_parsed = used_ - off_; size_t not_parsed = m_used - m_off;
while(next_size < size + not_parsed + COUNTER_SIZE) { while(next_size < size + not_parsed + COUNTER_SIZE) {
next_size *= 2; next_size *= 2;
} }
@@ -977,42 +977,42 @@ inline void unpacker::expand_buffer(size_t size)
detail::init_count(tmp); detail::init_count(tmp);
::memcpy(tmp+COUNTER_SIZE, buffer_ + off_, not_parsed); ::memcpy(tmp+COUNTER_SIZE, m_buffer + m_off, not_parsed);
if(ctx_.user().referenced()) { if(m_ctx.user().referenced()) {
try { try {
z_->push_finalizer(&detail::decl_count, buffer_); m_z->push_finalizer(&detail::decl_count, m_buffer);
} }
catch (...) { catch (...) {
::free(tmp); ::free(tmp);
throw; throw;
} }
ctx_.user().set_referenced(false); m_ctx.user().set_referenced(false);
} else { } else {
detail::decl_count(buffer_); detail::decl_count(m_buffer);
} }
buffer_ = tmp; m_buffer = tmp;
used_ = not_parsed + COUNTER_SIZE; m_used = not_parsed + COUNTER_SIZE;
free_ = next_size - used_; m_free = next_size - m_used;
off_ = COUNTER_SIZE; m_off = COUNTER_SIZE;
} }
} }
inline char* unpacker::buffer() inline char* unpacker::buffer()
{ {
return buffer_ + used_; return m_buffer + m_used;
} }
inline size_t unpacker::buffer_capacity() const inline size_t unpacker::buffer_capacity() const
{ {
return free_; return m_free;
} }
inline void unpacker::buffer_consumed(size_t size) inline void unpacker::buffer_consumed(size_t size)
{ {
used_ += size; m_used += size;
free_ -= size; m_free -= size;
} }
inline bool unpacker::next(unpacked* result) inline bool unpacker::next(unpacked* result)
@@ -1051,17 +1051,17 @@ inline bool unpacker::execute()
inline int unpacker::execute_imp() inline int unpacker::execute_imp()
{ {
size_t off = off_; size_t off = m_off;
int ret = ctx_.execute(buffer_, used_, off_); int ret = m_ctx.execute(m_buffer, m_used, m_off);
if(off_ > off) { if(m_off > off) {
parsed_ += off_ - off; m_parsed += m_off - off;
} }
return ret; return ret;
} }
inline object const& unpacker::data() inline object const& unpacker::data()
{ {
return ctx_.data(); return m_ctx.data();
} }
inline zone* unpacker::release_zone() inline zone* unpacker::release_zone()
@@ -1075,29 +1075,29 @@ inline zone* unpacker::release_zone()
return nullptr; return nullptr;
} }
zone* old = z_; zone* old = m_z;
z_ = r; m_z = r;
ctx_.user().set_zone(*z_); m_ctx.user().set_zone(*m_z);
return old; return old;
} }
inline void unpacker::reset_zone() inline void unpacker::reset_zone()
{ {
z_->clear(); m_z->clear();
} }
inline bool unpacker::flush_zone() inline bool unpacker::flush_zone()
{ {
if(ctx_.user().referenced()) { if(m_ctx.user().referenced()) {
try { try {
z_->push_finalizer(&detail::decl_count, buffer_); m_z->push_finalizer(&detail::decl_count, m_buffer);
} catch (...) { } catch (...) {
return false; return false;
} }
ctx_.user().set_referenced(false); m_ctx.user().set_referenced(false);
detail::incr_count(buffer_); detail::incr_count(m_buffer);
} }
return true; return true;
@@ -1105,39 +1105,39 @@ inline bool unpacker::flush_zone()
inline void unpacker::reset() inline void unpacker::reset()
{ {
ctx_.init(); m_ctx.init();
// don't reset referenced flag // don't reset referenced flag
parsed_ = 0; m_parsed = 0;
} }
inline size_t unpacker::message_size() const inline size_t unpacker::message_size() const
{ {
return parsed_ - off_ + used_; return m_parsed - m_off + m_used;
} }
inline size_t unpacker::parsed_size() const inline size_t unpacker::parsed_size() const
{ {
return parsed_; return m_parsed;
} }
inline char* unpacker::nonparsed_buffer() inline char* unpacker::nonparsed_buffer()
{ {
return buffer_ + off_; return m_buffer + m_off;
} }
inline size_t unpacker::nonparsed_size() const inline size_t unpacker::nonparsed_size() const
{ {
return used_ - off_; return m_used - m_off;
} }
inline void unpacker::skip_nonparsed_buffer(size_t size) inline void unpacker::skip_nonparsed_buffer(size_t size)
{ {
off_ += size; m_off += size;
} }
inline void unpacker::remove_nonparsed_buffer() inline void unpacker::remove_nonparsed_buffer()
{ {
used_ = off_; m_used = m_off;
} }
namespace detail { namespace detail {

View File

@@ -57,7 +57,7 @@ private:
public: public:
vrefbuffer(size_t ref_size = MSGPACK_VREFBUFFER_REF_SIZE, vrefbuffer(size_t ref_size = MSGPACK_VREFBUFFER_REF_SIZE,
size_t chunk_size = MSGPACK_VREFBUFFER_CHUNK_SIZE) size_t chunk_size = MSGPACK_VREFBUFFER_CHUNK_SIZE)
:ref_size_(ref_size), chunk_size_(chunk_size) :m_ref_size(ref_size), m_chunk_size(chunk_size)
{ {
size_t nfirst = (sizeof(iovec) < 72/2) ? size_t nfirst = (sizeof(iovec) < 72/2) ?
72 / sizeof(iovec) : 8; 72 / sizeof(iovec) : 8;
@@ -68,16 +68,16 @@ public:
throw std::bad_alloc(); throw std::bad_alloc();
} }
tail_ = array; m_tail = array;
end_ = array + nfirst; m_end = array + nfirst;
array_ = array; m_array = array;
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size)); chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
if(!c) { if(!c) {
::free(array); ::free(array);
throw std::bad_alloc(); throw std::bad_alloc();
} }
inner_buffer* const ib = &inner_buffer_; inner_buffer* const ib = &m_inner_buffer;
ib->free = chunk_size; ib->free = chunk_size;
ib->ptr = reinterpret_cast<char*>(c) + sizeof(chunk); ib->ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
@@ -88,7 +88,7 @@ public:
~vrefbuffer() ~vrefbuffer()
{ {
chunk* c = inner_buffer_.head; chunk* c = m_inner_buffer.head;
while(true) { while(true) {
chunk* n = c->next; chunk* n = c->next;
::free(c); ::free(c);
@@ -98,13 +98,13 @@ public:
break; break;
} }
} }
::free(array_); ::free(m_array);
} }
public: public:
void write(const char* buf, size_t len) void write(const char* buf, size_t len)
{ {
if(len < ref_size_) { if(len < m_ref_size) {
append_copy(buf, len); append_copy(buf, len);
} else { } else {
append_ref(buf, len); append_ref(buf, len);
@@ -113,32 +113,32 @@ public:
void append_ref(const char* buf, size_t len) void append_ref(const char* buf, size_t len)
{ {
if(tail_ == end_) { if(m_tail == m_end) {
const size_t nused = tail_ - array_; const size_t nused = m_tail - m_array;
const size_t nnext = nused * 2; const size_t nnext = nused * 2;
iovec* nvec = static_cast<iovec*>(::realloc( iovec* nvec = static_cast<iovec*>(::realloc(
array_, sizeof(iovec)*nnext)); m_array, sizeof(iovec)*nnext));
if(!nvec) { if(!nvec) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
array_ = nvec; m_array = nvec;
end_ = nvec + nnext; m_end = nvec + nnext;
tail_ = nvec + nused; m_tail = nvec + nused;
} }
tail_->iov_base = const_cast<char*>(buf); m_tail->iov_base = const_cast<char*>(buf);
tail_->iov_len = len; m_tail->iov_len = len;
++tail_; ++m_tail;
} }
void append_copy(const char* buf, size_t len) void append_copy(const char* buf, size_t len)
{ {
inner_buffer* const ib = &inner_buffer_; inner_buffer* const ib = &m_inner_buffer;
if(ib->free < len) { if(ib->free < len) {
size_t sz = chunk_size_; size_t sz = m_chunk_size;
if(sz < len) { if(sz < len) {
sz = len; sz = len;
} }
@@ -159,11 +159,11 @@ public:
ib->free -= len; ib->free -= len;
ib->ptr += len; ib->ptr += len;
if(tail_ != array_ && m == if(m_tail != m_array && m ==
static_cast<const char*>( static_cast<const char*>(
const_cast<const void *>((tail_ - 1)->iov_base) const_cast<const void *>((m_tail - 1)->iov_base)
) + (tail_ - 1)->iov_len) { ) + (m_tail - 1)->iov_len) {
(tail_ - 1)->iov_len += len; (m_tail - 1)->iov_len += len;
return; return;
} else { } else {
append_ref( m, len); append_ref( m, len);
@@ -172,17 +172,17 @@ public:
const struct iovec* vector() const const struct iovec* vector() const
{ {
return array_; return m_array;
} }
size_t vector_size() const size_t vector_size() const
{ {
return tail_ - array_; return m_tail - m_array;
} }
void migrate(vrefbuffer* to) void migrate(vrefbuffer* to)
{ {
size_t sz = chunk_size_; size_t sz = m_chunk_size;
chunk* empty = static_cast<chunk*>(::malloc(sizeof(chunk) + sz)); chunk* empty = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
if(!empty) { if(!empty) {
@@ -191,35 +191,35 @@ public:
empty->next = nullptr; empty->next = nullptr;
const size_t nused = tail_ - array_; const size_t nused = m_tail - m_array;
if(to->tail_ + nused < end_) { if(to->m_tail + nused < m_end) {
const size_t tosize = to->tail_ - to->array_; const size_t tosize = to->m_tail - to->m_array;
const size_t reqsize = nused + tosize; const size_t reqsize = nused + tosize;
size_t nnext = (to->end_ - to->array_) * 2; size_t nnext = (to->m_end - to->m_array) * 2;
while(nnext < reqsize) { while(nnext < reqsize) {
nnext *= 2; nnext *= 2;
} }
iovec* nvec = static_cast<iovec*>(::realloc( iovec* nvec = static_cast<iovec*>(::realloc(
to->array_, sizeof(iovec)*nnext)); to->m_array, sizeof(iovec)*nnext));
if(!nvec) { if(!nvec) {
::free(empty); ::free(empty);
throw std::bad_alloc(); throw std::bad_alloc();
} }
to->array_ = nvec; to->m_array = nvec;
to->end_ = nvec + nnext; to->m_end = nvec + nnext;
to->tail_ = nvec + tosize; to->m_tail = nvec + tosize;
} }
::memcpy(to->tail_, array_, sizeof(iovec)*nused); ::memcpy(to->m_tail, m_array, sizeof(iovec)*nused);
to->tail_ += nused; to->m_tail += nused;
tail_ = array_; m_tail = m_array;
inner_buffer* const ib = &inner_buffer_; inner_buffer* const ib = &m_inner_buffer;
inner_buffer* const toib = &to->inner_buffer_; inner_buffer* const toib = &to->m_inner_buffer;
chunk* last = ib->head; chunk* last = ib->head;
while(last->next) { while(last->next) {
@@ -241,7 +241,7 @@ public:
void clear() void clear()
{ {
chunk* c = inner_buffer_.head->next; chunk* c = m_inner_buffer.head->next;
chunk* n; chunk* n;
while(c) { while(c) {
n = c->next; n = c->next;
@@ -249,27 +249,27 @@ public:
c = n; c = n;
} }
inner_buffer* const ib = &inner_buffer_; inner_buffer* const ib = &m_inner_buffer;
c = ib->head; c = ib->head;
c->next = nullptr; c->next = nullptr;
ib->free = chunk_size_; ib->free = m_chunk_size;
ib->ptr = reinterpret_cast<char*>(c) + sizeof(chunk); ib->ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
tail_ = array_; m_tail = m_array;
} }
private: private:
vrefbuffer(const vrefbuffer&); vrefbuffer(const vrefbuffer&);
private: private:
iovec* tail_; iovec* m_tail;
iovec* end_; iovec* m_end;
iovec* array_; iovec* m_array;
size_t ref_size_; size_t m_ref_size;
size_t chunk_size_; size_t m_chunk_size;
inner_buffer inner_buffer_; inner_buffer m_inner_buffer;
}; };

View File

@@ -36,49 +36,49 @@ class zbuffer {
public: public:
zbuffer(int level = Z_DEFAULT_COMPRESSION, zbuffer(int level = Z_DEFAULT_COMPRESSION,
size_t init_size = MSGPACK_ZBUFFER_INIT_SIZE) size_t init_size = MSGPACK_ZBUFFER_INIT_SIZE)
: data_(nullptr), init_size_(init_size) : m_data(nullptr), m_init_size(init_size)
{ {
stream_.zalloc = Z_NULL; m_stream.zalloc = Z_NULL;
stream_.zfree = Z_NULL; m_stream.zfree = Z_NULL;
stream_.opaque = Z_NULL; m_stream.opaque = Z_NULL;
stream_.next_out = Z_NULL; m_stream.next_out = Z_NULL;
stream_.avail_out = 0; m_stream.avail_out = 0;
if(deflateInit(&stream_, level) != Z_OK) { if(deflateInit(&m_stream, level) != Z_OK) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
} }
~zbuffer() ~zbuffer()
{ {
deflateEnd(&stream_); deflateEnd(&m_stream);
::free(data_); ::free(m_data);
} }
public: public:
void write(const char* buf, size_t len) void write(const char* buf, size_t len)
{ {
stream_.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(buf)); m_stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(buf));
stream_.avail_in = len; m_stream.avail_in = len;
do { do {
if(stream_.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) { if(m_stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) {
if(!expand()) { if(!expand()) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
} }
if(deflate(&stream_, Z_NO_FLUSH) != Z_OK) { if(deflate(&m_stream, Z_NO_FLUSH) != Z_OK) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
} while(stream_.avail_in > 0); } while(m_stream.avail_in > 0);
} }
char* flush() char* flush()
{ {
while(true) { while(true) {
switch(deflate(&stream_, Z_FINISH)) { switch(deflate(&m_stream, Z_FINISH)) {
case Z_STREAM_END: case Z_STREAM_END:
return data_; return m_data;
case Z_OK: case Z_OK:
if(!expand()) { if(!expand()) {
throw std::bad_alloc(); throw std::bad_alloc();
@@ -92,22 +92,22 @@ public:
char* data() char* data()
{ {
return data_; return m_data;
} }
const char* data() const const char* data() const
{ {
return data_; return m_data;
} }
size_t size() const size_t size() const
{ {
return reinterpret_cast<char*>(stream_.next_out) - data_; return reinterpret_cast<char*>(m_stream.next_out) - m_data;
} }
void reset() void reset()
{ {
if(deflateReset(&stream_) != Z_OK) { if(deflateReset(&m_stream) != Z_OK) {
throw std::bad_alloc(); throw std::bad_alloc();
} }
reset_buffer(); reset_buffer();
@@ -115,34 +115,34 @@ public:
void reset_buffer() void reset_buffer()
{ {
stream_.avail_out += reinterpret_cast<char*>(stream_.next_out) - data_; m_stream.avail_out += reinterpret_cast<char*>(m_stream.next_out) - m_data;
stream_.next_out = reinterpret_cast<Bytef*>(data_); m_stream.next_out = reinterpret_cast<Bytef*>(m_data);
} }
char* release_buffer() char* release_buffer()
{ {
char* tmp = data_; char* tmp = m_data;
data_ = nullptr; m_data = nullptr;
stream_.next_out = nullptr; m_stream.next_out = nullptr;
stream_.avail_out = 0; m_stream.avail_out = 0;
return tmp; return tmp;
} }
private: private:
bool expand() bool expand()
{ {
size_t used = reinterpret_cast<char*>(stream_.next_out) - data_; size_t used = reinterpret_cast<char*>(m_stream.next_out) - m_data;
size_t csize = used + stream_.avail_out; size_t csize = used + m_stream.avail_out;
size_t nsize = (csize == 0) ? init_size_ : csize * 2; size_t nsize = (csize == 0) ? m_init_size : csize * 2;
char* tmp = static_cast<char*>(::realloc(data_, nsize)); char* tmp = static_cast<char*>(::realloc(m_data, nsize));
if(tmp == nullptr) { if(tmp == nullptr) {
return false; return false;
} }
data_ = tmp; m_data = tmp;
stream_.next_out = reinterpret_cast<Bytef*>(tmp + used); m_stream.next_out = reinterpret_cast<Bytef*>(tmp + used);
stream_.avail_out = nsize - used; m_stream.avail_out = nsize - used;
return true; return true;
} }
@@ -150,9 +150,9 @@ private:
zbuffer(const zbuffer&); zbuffer(const zbuffer&);
private: private:
z_stream stream_; z_stream m_stream;
char* data_; char* m_data;
size_t init_size_; size_t m_init_size;
}; };