Skip to content

Commit

Permalink
buffer: add operator= for ptr/bufferlist rvalue
Browse files Browse the repository at this point in the history
Signed-off-by: Haomai Wang <haomai@xsky.com>
  • Loading branch information
yuyuyu101 committed Feb 2, 2016
1 parent 928bf1d commit 4c17b1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,21 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
}
return *this;
}
buffer::ptr& buffer::ptr::operator= (ptr&& p)
{
release();
buffer::raw *raw = p._raw;
if (raw) {
_raw = raw;
_off = p._off;
_len = p._len;
p._raw = nullptr;
p._off = p._len = 0;
} else {
_off = _len = 0;
}
return *this;
}

buffer::raw *buffer::ptr::clone()
{
Expand Down
11 changes: 11 additions & 0 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ namespace buffer CEPH_BUFFER_API {
ptr(ptr&& p);
ptr(const ptr& p, unsigned o, unsigned l);
ptr& operator= (const ptr& p);
ptr& operator= (ptr&& p);
~ptr() {
release();
}
Expand Down Expand Up @@ -377,6 +378,16 @@ namespace buffer CEPH_BUFFER_API {
return *this;
}

list& operator= (list&& other) {
_buffers = std::move(other._buffers);
_len = other._len;
_memcopy_count = other._memcopy_count;
last_p = begin();
append_buffer.swap(other.append_buffer);
other.clear();
return *this;
}

unsigned get_memcopy_count() const {return _memcopy_count; }
const std::list<ptr>& buffers() const { return _buffers; }
void swap(list& other);
Expand Down

0 comments on commit 4c17b1d

Please sign in to comment.