Skip to content

avoid redundant memcopy in node_buffer::get_nodes - #23

Merged
arvidn merged 2 commits into
bittorrent:masterfrom
arvidn:node-buffer_optimization
Aug 22, 2016
Merged

avoid redundant memcopy in node_buffer::get_nodes#23
arvidn merged 2 commits into
bittorrent:masterfrom
arvidn:node-buffer_optimization

Conversation

@arvidn

@arvidn arvidn commented Aug 21, 2016

Copy link
Copy Markdown
Contributor

Instead of heap allocating a string and copying nodes into, this patch makes node_buffer::get_nodes() return 2 ranges of bytes to be copied into the packet. This avoids heap allocations entirely and saves at least one memcopy for all node data.

@arvidn

arvidn commented Aug 21, 2016

Copy link
Copy Markdown
Contributor Author

@arvidn
arvidn force-pushed the node-buffer_optimization branch from cbfcd51 to 0b11328 Compare August 22, 2016 17:01
@arvidn

arvidn commented Aug 22, 2016

Copy link
Copy Markdown
Contributor Author

Comment thread node_buffer.hpp Outdated
{
std::string ret;

if (m_buffer.size() < num_nodes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comparison should be <=. No point in returning two ranges if they're going to comprise the entire buffer.

@ssiloti

ssiloti commented Aug 22, 2016

Copy link
Copy Markdown
Contributor

lgtm

@arvidn
arvidn merged commit 1222e75 into bittorrent:master Aug 22, 2016
@arvidn
arvidn deleted the node-buffer_optimization branch August 22, 2016 18:18
@arvidn

arvidn commented Aug 23, 2016

Copy link
Copy Markdown
Contributor Author

actually, changing that comparison operator made the unit test fail. I'll fix that in-place in the master branch (since I already merged it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants