-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buffer: use move construct to append/push_back/push_front #7455
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dd4e6e1
buffer: add ptr move construct
yuyuyu101 0305cee
misc: using move construct to avoid extra atomic inc/dec
yuyuyu101 669f143
buffer: add operator= for ptr/bufferlist rvalue
yuyuyu101 41c3dc2
test_bufferlist: add move tests for bufferlist
yuyuyu101 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,8 +174,10 @@ namespace buffer CEPH_BUFFER_API { | |
ptr(unsigned l); | ||
ptr(const char *d, unsigned l); | ||
ptr(const ptr& p); | ||
ptr(ptr&& p); | ||
ptr(const ptr& p, unsigned o, unsigned l); | ||
ptr& operator= (const ptr& p); | ||
ptr& operator= (ptr&& p); | ||
~ptr() { | ||
release(); | ||
} | ||
|
@@ -376,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); | ||
|
@@ -417,19 +429,29 @@ namespace buffer CEPH_BUFFER_API { | |
_buffers.push_front(bp); | ||
_len += bp.length(); | ||
} | ||
void push_front(ptr&& bp) { | ||
if (bp.length() == 0) | ||
return; | ||
_len += bp.length(); | ||
_buffers.push_front(std::move(bp)); | ||
} | ||
void push_front(raw *r) { | ||
ptr bp(r); | ||
push_front(bp); | ||
push_front(ptr(r)); | ||
} | ||
void push_back(const ptr& bp) { | ||
if (bp.length() == 0) | ||
return; | ||
_buffers.push_back(bp); | ||
_len += bp.length(); | ||
} | ||
void push_back(ptr&& bp) { | ||
if (bp.length() == 0) | ||
return; | ||
_len += bp.length(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment for push_front() |
||
_buffers.push_back(std::move(bp)); | ||
} | ||
void push_back(raw *r) { | ||
ptr bp(r); | ||
push_back(bp); | ||
push_back(ptr(r)); | ||
} | ||
|
||
void zero(); | ||
|
@@ -500,6 +522,7 @@ namespace buffer CEPH_BUFFER_API { | |
append(s.data(), s.length()); | ||
} | ||
void append(const ptr& bp); | ||
void append(ptr&& bp); | ||
void append(const ptr& bp, unsigned off, unsigned len); | ||
void append(const list& bl); | ||
void append(std::istream& in); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, need to
std::move(bp)
when passing it to push_front(). then you'll need to call to bp.length() before it moves away: