From e381288146c89250655507e2bc1e8771dd9672bb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 14 Dec 2021 22:03:02 +0100 Subject: [PATCH] QRingBuffer: restrict QRingChunk::toByteArray() calls to rvalue *this MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's only user, QRingBuffer::read(), calls it on an rvalue, so we don't need the lvalue overload, and we can devil-may-care-like just std::move(chunk) in the non-isShared() case. Change-Id: I99c16862f5586125c6346ce5f969dc735de738b8 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qringbuffer.cpp | 4 ++-- src/corelib/tools/qringbuffer_p.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index f59dcc39c4d..f32673b9bd7 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -62,7 +62,7 @@ void QRingChunk::detach() tailOffset = chunkSize; } -QByteArray QRingChunk::toByteArray() +QByteArray QRingChunk::toByteArray() && { if (headOffset != 0 || tailOffset != chunk.size()) { if (isShared()) @@ -79,7 +79,7 @@ QByteArray QRingChunk::toByteArray() chunk.resize(tailOffset); } - return chunk; + return std::move(chunk); } /*! diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index d01c31b8617..1ab0053d1ac 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -114,7 +114,7 @@ public: return !chunk.isDetached(); } Q_CORE_EXPORT void detach(); - QByteArray toByteArray(); + QByteArray toByteArray() &&; // getters inline qsizetype head() const