From 735e2f787acf1f74c00e26730c7a477a7a59129f 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 [1/2] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let the compiler generate the copy and move SMFs. Statically assert that the move SMFs are still noexcept. Pick-to: 6.3 Change-Id: I1c569bdf893a5f2cda972c0dd8196cab62494fcb Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qringbuffer.cpp | 8 +++++++- src/corelib/tools/qringbuffer_p.h | 20 +------------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index f32673b9bd7..b10362b0cdb 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Copyright (C) 2015 Alex Trotsenko ** Contact: https://www.qt.io/licensing/ ** @@ -40,10 +40,16 @@ #include "private/qringbuffer_p.h" #include "private/qbytearray_p.h" + +#include + #include QT_BEGIN_NAMESPACE +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); + void QRingChunk::allocate(qsizetype alloc) { Q_ASSERT(alloc > 0 && size() == 0); diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 1ab0053d1ac..84e0f9ddec5 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -69,10 +69,6 @@ public: headOffset(0), tailOffset(0) { } - inline QRingChunk(const QRingChunk &other) noexcept : - chunk(other.chunk), headOffset(other.headOffset), tailOffset(other.tailOffset) - { - } explicit inline QRingChunk(qsizetype alloc) : chunk(alloc, Qt::Uninitialized), headOffset(0), tailOffset(0) { @@ -86,20 +82,6 @@ public: { } - inline QRingChunk &operator=(const QRingChunk &other) noexcept - { - chunk = other.chunk; - headOffset = other.headOffset; - tailOffset = other.tailOffset; - return *this; - } - inline QRingChunk(QRingChunk &&other) noexcept : - chunk(other.chunk), headOffset(other.headOffset), tailOffset(other.tailOffset) - { - other.headOffset = other.tailOffset = 0; - } - QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRingChunk) - inline void swap(QRingChunk &other) noexcept { chunk.swap(other.chunk);