diff --git a/include/connectionimpl.h b/include/connectionimpl.h index a2cd2fa..aaa8efa 100644 --- a/include/connectionimpl.h +++ b/include/connectionimpl.h @@ -348,7 +348,7 @@ public: * * @param buffer the buffer with data to send */ - bool send(const CopiedBuffer &buffer); + bool send(CopiedBuffer &&buffer); /** * Get a channel by its identifier diff --git a/include/copiedbuffer.h b/include/copiedbuffer.h index 8069406..0716483 100644 --- a/include/copiedbuffer.h +++ b/include/copiedbuffer.h @@ -82,17 +82,10 @@ public: } /** - * Copy constructor + * Disabled copy constructor to prevent expensive copy operations * @param that */ - CopiedBuffer(const CopiedBuffer &that) : - _capacity(that._capacity), - _buffer((char *)malloc(_capacity)), - _size(that._size) - { - // copy the data - memcpy(_buffer, that._buffer, _size); - } + CopiedBuffer(const CopiedBuffer &that) = delete; /** * Move constructor diff --git a/src/channelimpl.cpp b/src/channelimpl.cpp index e0fc251..1ddf54f 100644 --- a/src/channelimpl.cpp +++ b/src/channelimpl.cpp @@ -727,15 +727,15 @@ void ChannelImpl::onSynchronized() while (_connection && !_synchronous && !_queue.empty()) { // retrieve the first buffer and synchronous - const auto &pair = _queue.front(); + auto &pair = _queue.front(); // mark as synchronous if necessary _synchronous = pair.first; // send it over the connection - _connection->send(pair.second); + _connection->send(std::move(pair.second)); - // the user space handler may have destructed the channel + // the user space handler may have destructed this channel object if (!monitor.valid()) return; // remove from the list diff --git a/src/connectionimpl.cpp b/src/connectionimpl.cpp index f6ab8e3..ca81a1f 100644 --- a/src/connectionimpl.cpp +++ b/src/connectionimpl.cpp @@ -353,7 +353,7 @@ bool ConnectionImpl::send(const Frame &frame) * * @param buffer the buffer with data to send */ -bool ConnectionImpl::send(const CopiedBuffer &buffer) +bool ConnectionImpl::send(CopiedBuffer &&buffer) { // this only works when we are already connected if (_state != state_connected) return false; @@ -367,7 +367,7 @@ bool ConnectionImpl::send(const CopiedBuffer &buffer) else { // add to the list of waiting buffers - _queue.push(buffer); + _queue.emplace(std::move(buffer)); } // done