From 89d89f99a794d8edf9282e76a95f78c28ab4d932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Brooke?= Date: Fri, 12 Jan 2024 16:02:16 +0100 Subject: [PATCH] QShader: add move constructor, move-assignment operator and swap [ChangeLog][QtGui][QShader] Added move constructor, move-assignment operator and swap member function. Pick-to: 6.7 Change-Id: I25dbaf4cdd1190204d23121e6ecd8e3947c4b612 Reviewed-by: Marc Mutz --- src/gui/rhi/qshader.cpp | 30 ++++++++++++++++++++++++++++++ src/gui/rhi/qshader.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/src/gui/rhi/qshader.cpp b/src/gui/rhi/qshader.cpp index 14e33d2d43e..d5fb53e7e6a 100644 --- a/src/gui/rhi/qshader.cpp +++ b/src/gui/rhi/qshader.cpp @@ -298,6 +298,28 @@ QShader &QShader::operator=(const QShader &other) return *this; } +/*! + \fn QShader::QShader(QShader &&other) noexcept + \since 6.7 + + Move-constructs a new QShader from \a other. + + \note The moved-from object \a other is placed in a + partially-formed state, in which the only valid operations are + destruction and assignment of a new value. +*/ + +/*! + \fn QShader &QShader::operator=(QShader &&other) + \since 6.7 + + Move-assigns \a other to this QShader instance. + + \note The moved-from object \a other is placed in a + partially-formed state, in which the only valid operations are + destruction and assignment of a new value. +*/ + /*! Destructor. */ @@ -307,6 +329,14 @@ QShader::~QShader() delete d; } +/*! + \fn void QShader::swap(QShader &other) + \since 6.7 + + Swaps shader \a other with this shader. This operation is very fast and + never fails. +*/ + /*! \return true if the QShader contains at least one shader version. */ diff --git a/src/gui/rhi/qshader.h b/src/gui/rhi/qshader.h index 0b52022596c..24650813667 100644 --- a/src/gui/rhi/qshader.h +++ b/src/gui/rhi/qshader.h @@ -117,7 +117,11 @@ public: QShader(); QShader(const QShader &other); QShader &operator=(const QShader &other); + QShader(QShader &&other) noexcept : d(std::exchange(other.d, nullptr)) {} + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QShader) ~QShader(); + + void swap(QShader &other) noexcept { qt_ptr_swap(d, other.d); } void detach(); bool isValid() const;