From 48b4f144e7f690f5ae840124eaad4eaa67a02681 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 13 Dec 2021 12:29:51 +0100 Subject: [PATCH] QRingBuffer: simplify QRingChunk special member functions [2/2] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use NSDMI and let the compiler generate the default ctor, too. Statically assert that it's still noexcept (we marked it as such, because MSVC still doesn't noexcept(auto) when an SMF is =default'ed. Simplify the other ctors, too, relying on NSDMI. Keep one instance of tailOffset(0), in the 'reserving' ctor, because it's inconsistent with the other ctors which all do tailOffset{chunk.size()}, so it's best to leave this explicit, lest the next reader wonders whether it was forgotten. Pick-to: 6.3 Change-Id: I0d9f91aa5bc89377c4144589df8786b502e956a4 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qringbuffer.cpp | 1 + src/corelib/tools/qringbuffer_p.h | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index b10362b0cd..72c56a20f6 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE +static_assert(std::is_nothrow_default_constructible_v); static_assert(std::is_nothrow_move_constructible_v); static_assert(std::is_nothrow_move_assignable_v); diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 84e0f9ddec..58430b5a68 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -65,20 +65,17 @@ class QRingChunk { public: // initialization and cleanup - inline QRingChunk() noexcept : - headOffset(0), tailOffset(0) - { - } + QRingChunk() noexcept = default; explicit inline QRingChunk(qsizetype alloc) : - chunk(alloc, Qt::Uninitialized), headOffset(0), tailOffset(0) + chunk(alloc, Qt::Uninitialized), tailOffset(0) { } explicit inline QRingChunk(const QByteArray &qba) noexcept : - chunk(qba), headOffset(0), tailOffset(qba.size()) + chunk(qba), tailOffset(qba.size()) { } explicit QRingChunk(QByteArray &&qba) noexcept : - chunk(std::move(qba)), headOffset(0), tailOffset(chunk.size()) + chunk(std::move(qba)), tailOffset(chunk.size()) { } @@ -164,8 +161,8 @@ public: private: QByteArray chunk; - qsizetype headOffset; - qsizetype tailOffset; + qsizetype headOffset = 0; + qsizetype tailOffset = 0; }; Q_DECLARE_SHARED(QRingChunk)