diff options
author | luigi1111 <luigi1111w@gmail.com> | 2020-05-01 15:13:58 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2020-05-01 15:13:58 -0500 |
commit | 3e21e591b8201fdb852822b1d30faa1fb97d870a (patch) | |
tree | 66f7e7af1eb010d5ed97320916b40abc58a36268 /contrib/epee/src/byte_slice.cpp | |
parent | Merge pull request #6487 (diff) | |
parent | Use byte_slice for sending zmq messages - removes data copy within zmq (diff) | |
download | monero-3e21e591b8201fdb852822b1d30faa1fb97d870a.tar.xz |
Merge pull request #6350
da99157 Use byte_slice for sending zmq messages - removes data copy within zmq (vtnerd)
Diffstat (limited to 'contrib/epee/src/byte_slice.cpp')
-rw-r--r-- | contrib/epee/src/byte_slice.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
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<std::size_t> 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<byte_slice_data*>(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_data, release_byte_slice> byte_slice::take_buffer() noexcept + { + std::unique_ptr<byte_slice_data, release_byte_slice> out{std::move(storage_)}; + portion_ = nullptr; + return out; + } } // epee |