From: Kefu Chai Date: Thu, 10 Sep 2015 19:51:36 +0000 (-0700) Subject: common/buffer: add the move constructor for bufferlist X-Git-Tag: v9.1.0~130^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a795c885e9f5e1292577d6e95f98308cbd04a8fb;p=ceph.git common/buffer: add the move constructor for bufferlist Signed-off-by: Kefu Chai --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index d02013b81620..a7ed8883f0e5 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1105,6 +1105,15 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; // -- buffer::list -- + buffer::list::list(list&& other) + : _buffers(std::move(other._buffers)), + _len(other._len), + _memcopy_count(other._memcopy_count), + last_p(this) { + append_buffer.swap(other.append_buffer); + other.clear(); + } + void buffer::list::swap(list& other) { std::swap(_len, other._len); diff --git a/src/include/buffer.h b/src/include/buffer.h index 007d8d6ca10d..854a28635812 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -347,6 +347,7 @@ public: _memcopy_count(other._memcopy_count), last_p(this) { make_shareable(); } + list(list&& other); list& operator= (const list& other) { if (this != &other) { _buffers = other._buffers; diff --git a/src/test/bufferlist.cc b/src/test/bufferlist.cc index 43cb6543f493..b05a15a4eca0 100644 --- a/src/test/bufferlist.cc +++ b/src/test/bufferlist.cc @@ -1128,6 +1128,17 @@ TEST(BufferList, constructors) { bufferlist copy(bl); ASSERT_EQ('A', copy[0]); } + // + // list(list&& other) + // + { + bufferlist bl(1); + bl.append('A'); + bufferlist copy = std::move(bl); + ASSERT_EQ(0U, bl.length()); + ASSERT_EQ(1U, copy.length()); + ASSERT_EQ('A', copy[0]); + } } TEST(BufferList, operator_equal) {