summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-13 12:29:51 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-17 07:52:40 +0000
commit48b4f144e7f690f5ae840124eaad4eaa67a02681 (patch)
tree5d7265f145d116ce58ca41472dfc9a76aaf8a373
parent38e7b5dcd684df80ea3edbbae236d7bdebf49b8c (diff)
QRingBuffer: simplify QRingChunk special member functions [2/2]
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 <marten.nordheim@qt.io>
-rw-r--r--src/corelib/tools/qringbuffer.cpp1
-rw-r--r--src/corelib/tools/qringbuffer_p.h15
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<QRingChunk>);
static_assert(std::is_nothrow_move_constructible_v<QRingChunk>);
static_assert(std::is_nothrow_move_assignable_v<QRingChunk>);
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)