]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer: add the move constructor for bufferlist 5096/head
authorKefu Chai <kchai@redhat.com>
Thu, 10 Sep 2015 19:51:36 +0000 (12:51 -0700)
committerKefu Chai <kchai@redhat.com>
Thu, 10 Sep 2015 20:13:41 +0000 (13:13 -0700)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/buffer.cc
src/include/buffer.h
src/test/bufferlist.cc

index d02013b816202cd92bf1b0813fd6256cb8524b2f..a7ed8883f0e58c6bd1243d009ed12e0da1b55f0b 100644 (file)
@@ -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);
index 007d8d6ca10d476e415d71f0f839a257f54cae91..854a286358128ae29e6804dc4cf01795e554d0ba 100644 (file)
@@ -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;
index 43cb6543f493fb94128bb3c18ef806fef125fb10..b05a15a4eca00909c911eeff03d1d1c6361badd0 100644 (file)
@@ -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) {