From 758a830f7ef23ebea542bc6dad4490b29e22bab8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 13 Dec 2021 12:03:51 +0100 Subject: QRingBuffer: overload append() for rvalues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The majority of append() callers in QtBase pass rvalues, so overload append() to avoid the need for manipulating QBA's atomic ref counts. Also adjust a caller that could pass by rvalue, but didn't, to do so. Pick-to: 6.3 Change-Id: I3d9e60b0d04ef837bfdc526e1f0f691a151006f9 Reviewed-by: Oswald Buddenhagen Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qringbuffer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/corelib/tools/qringbuffer.cpp') diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index 09b0336145f..d46dcdffdff 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -363,6 +363,21 @@ void QRingBuffer::append(const QByteArray &qba) bufferSize += qba.size(); } +/*! + \internal + + Append a new buffer to the end +*/ +void QRingBuffer::append(QByteArray &&qba) +{ + const auto qbaSize = qba.size(); + if (bufferSize != 0 || buffers.isEmpty()) + buffers.emplace_back(std::move(qba)); + else + buffers.last().assign(std::move(qba)); + bufferSize += qbaSize; +} + qint64 QRingBuffer::readLine(char *data, qint64 maxLength) { Q_ASSERT(data != nullptr && maxLength > 1); -- cgit v1.2.3