From da9915746219482c25b96406d475c6fde9b02a31 Mon Sep 17 00:00:00 2001 From: Lee Clagett Date: Sun, 17 Nov 2019 06:06:10 +0000 Subject: Use byte_slice for sending zmq messages - removes data copy within zmq --- contrib/epee/src/byte_slice.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'contrib/epee/src/byte_slice.cpp') diff --git a/contrib/epee/src/byte_slice.cpp b/contrib/epee/src/byte_slice.cpp index 216049e5b..3ad3b3e7e 100644 --- a/contrib/epee/src/byte_slice.cpp +++ b/contrib/epee/src/byte_slice.cpp @@ -49,12 +49,16 @@ namespace epee std::atomic ref_count; }; - void release_byte_slice::operator()(byte_slice_data* ptr) const noexcept + void release_byte_slice::call(void*, void* ptr) noexcept { - if (ptr && --(ptr->ref_count) == 0) + if (ptr) { - ptr->~byte_slice_data(); - free(ptr); + byte_slice_data* self = static_cast(ptr); + if (--(self->ref_count) == 0) + { + self->~byte_slice_data(); + free(self); + } } } @@ -206,4 +210,11 @@ namespace epee return {}; return {storage_.get(), {portion_.begin() + begin, end - begin}}; } + + std::unique_ptr byte_slice::take_buffer() noexcept + { + std::unique_ptr out{std::move(storage_)}; + portion_ = nullptr; + return out; + } } // epee -- cgit v1.2.3