mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-29 07:25:55 +02:00
Re-implemented msgpack::unpacker's move operations.
I refered to the following article and comments. http://scottmeyers.blogspot.jp/2014/06/the-drawbacks-of-implementing-move.html msgpack::detail::context back to copiable. msgpack::detail::context doen't have any resource ownership, so there is no strong reason to avoid copy.
This commit is contained in:
parent
bfa428ab13
commit
09325ed846
@ -248,10 +248,6 @@ public:
|
|||||||
{
|
{
|
||||||
m_stack[0].set_obj(object());
|
m_stack[0].set_obj(object());
|
||||||
}
|
}
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
|
||||||
context(context&& other) = default;
|
|
||||||
context& operator=(context&& other) = default;
|
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
@ -725,9 +721,6 @@ private:
|
|||||||
unsigned int m_top;
|
unsigned int m_top;
|
||||||
unsigned int m_stack_idx;
|
unsigned int m_stack_idx;
|
||||||
unpack_stack m_stack[MSGPACK_EMBED_STACK_SIZE];
|
unpack_stack m_stack[MSGPACK_EMBED_STACK_SIZE];
|
||||||
private:
|
|
||||||
context(context const&);
|
|
||||||
context& operator=(context const&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
@ -949,14 +942,14 @@ inline unpacker::unpacker(unpacker&& other)
|
|||||||
m_parsed(other.m_parsed),
|
m_parsed(other.m_parsed),
|
||||||
m_z(other.m_z),
|
m_z(other.m_z),
|
||||||
m_initial_buffer_size(other.m_initial_buffer_size),
|
m_initial_buffer_size(other.m_initial_buffer_size),
|
||||||
m_ctx(msgpack::move(other.m_ctx)) {
|
m_ctx(other.m_ctx) {
|
||||||
other.m_buffer = nullptr;
|
other.m_buffer = nullptr;
|
||||||
other.m_z = nullptr;
|
other.m_z = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unpacker& unpacker::operator=(unpacker&& other) {
|
inline unpacker& unpacker::operator=(unpacker&& other) {
|
||||||
std::swap(m_z, other.m_z);
|
this->~unpacker();
|
||||||
std::swap(m_buffer, other.m_buffer);
|
new (this) unpacker(std::move(other));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user