From 81bf3e68b9edb6fc8635ab5520f86df9c8d6ef04 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 12 Dec 2021 17:04:26 +0100 Subject: Make QRingBuffer a move-only type There's no sense in copying a ring buffer. Moving is enough. This marks an important step on the way to preventing accidental copies of ring buffer content, because the 'QList buffers' member can now no longer be implicitly shared. While the compiler will still emit the code for detach()ing, it will now never be executed. Pick-to: 6.3 Change-Id: I968bfe3e50c46720ed4baca55c99c1f9c518f653 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp index 3b922de0ca..6efa39f4f5 100644 --- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp +++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp @@ -38,6 +38,7 @@ class tst_QRingBuffer : public QObject private slots: void constructing(); void usingInVector(); + void usingInVarLengthArray(); void readPointerAtPositionWriteRead(); void readPointerAtPositionEmptyRead(); void readPointerAtPositionWithHead(); @@ -83,10 +84,20 @@ void tst_QRingBuffer::constructing() void tst_QRingBuffer::usingInVector() { QRingBuffer ringBuffer; - QList buffers; + std::vector buffers; ringBuffer.reserve(5); - buffers.append(ringBuffer); + buffers.push_back(std::move(ringBuffer)); + QCOMPARE(buffers[0].size(), Q_INT64_C(5)); +} + +void tst_QRingBuffer::usingInVarLengthArray() +{ + QRingBuffer ringBuffer; + QVarLengthArray buffers; + + ringBuffer.reserve(5); + buffers.push_back(std::move(ringBuffer)); QCOMPARE(buffers[0].size(), Q_INT64_C(5)); } -- cgit v1.2.3