avoid redundant memcopy in node_buffer::get_nodes #23

merged 2 commits into from Aug 22, 2016


None yet

2 participants

arvidn commented Aug 21, 2016

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.

@ssiloti ssiloti commented on an outdated diff Aug 22, 2016
- std::string ret;
if (m_buffer.size() < num_nodes)
ssiloti Aug 22, 2016 Contributor

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

ssiloti commented Aug 22, 2016


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

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