From 246e7125485570416560d6a8503f785a31be1b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 5 May 2020 17:45:58 +0200 Subject: Move-enable QByteDataBuffer::{append,prepend} Change-Id: I2fd342465475e3a694c8459a54957149f8b418a9 Reviewed-by: Thiago Macieira --- src/corelib/text/qbytedata_p.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/corelib/text/qbytedata_p.h b/src/corelib/text/qbytedata_p.h index 108aec72ac..551edc8b1b 100644 --- a/src/corelib/text/qbytedata_p.h +++ b/src/corelib/text/qbytedata_p.h @@ -53,6 +53,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -90,25 +91,48 @@ public: popFront(buffers[bufferCount() - other.bufferCount()], other.firstPos); } + inline void append(QByteDataBuffer &&other) + { + if (other.isEmpty()) + return; + + auto otherBufferCount = other.bufferCount(); + auto otherByteAmount = other.byteAmount(); + buffers.append(std::move(other.buffers)); + bufferCompleteSize += otherByteAmount; + + if (other.firstPos > 0) + popFront(buffers[bufferCount() - otherBufferCount], other.firstPos); + } inline void append(const QByteArray& bd) + { + append(QByteArray(bd)); + } + + inline void append(QByteArray &&bd) { if (bd.isEmpty()) return; - buffers.append(bd); bufferCompleteSize += bd.size(); + buffers.append(std::move(bd)); } inline void prepend(const QByteArray& bd) + { + prepend(QByteArray(bd)); + } + + inline void prepend(QByteArray &&bd) { if (bd.isEmpty()) return; squeezeFirst(); - buffers.prepend(bd); bufferCompleteSize += bd.size(); + buffers.prepend(std::move(bd)); } // return the first QByteData. User of this function has to free() its .data! -- cgit v1.2.3