QDirListing: make move SMFs noexcept and inline

This requires giving up unique_ptr for a raw d-pointer:
https://stackoverflow.com/questions/9417477/where-does-the-destructor-hide-in-this-code

That isn't much of an issue, because the class is move-only.

Also add a swap() member function.

Found in API review.

Change-Id: I2478bb5d05ff7bae0111ba97e788c88f7b4dded1
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 71167b7982be4d7a9090aa6b0e0846d5e9bf303b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-08-27 00:32:53 +03:00 committed by Qt Cherry-pick Bot
parent e6ab7847a7
commit 054270c717
2 changed files with 15 additions and 8 deletions

View File

@ -605,6 +605,8 @@ QDirListing::QDirListing(const QString &path, const QStringList &nameFilters, ui
}
/*!
\fn QDirListing::QDirListing(QDirListing &&other)
Move constructor. Moves \a other into this QDirListing.
//! [partially-formed]
@ -613,20 +615,22 @@ QDirListing::QDirListing(const QString &path, const QStringList &nameFilters, ui
value.
//! [partially-formed]
*/
QDirListing::QDirListing(QDirListing &&other) = default;
/*!
\fn QDirListing &QDirListing::operator=(QDirListing &&other)
Move-assigns \a other to this QDirListing.
\include qdirlisting.cpp partially-formed
*/
QDirListing &QDirListing::operator=(QDirListing &&other) = default;
/*!
Destroys the QDirListing.
*/
QDirListing::~QDirListing() = default;
QDirListing::~QDirListing()
{
delete d;
}
/*!
Returns the directory path used to construct this QDirListing.
@ -690,7 +694,7 @@ QStringList QDirListing::nameFilters() const
QDirListing::const_iterator QDirListing::begin() const
{
d->beginIterating();
const_iterator it{d.get()};
const_iterator it{d};
return ++it;
}

View File

@ -45,8 +45,11 @@ public:
Q_CORE_EXPORT explicit QDirListing(const QString &path, const QStringList &nameFilters,
IteratorFlags flags = IteratorFlag::Default);
QDirListing(QDirListing &&);
QDirListing &operator=(QDirListing &&);
QDirListing(QDirListing &&other) noexcept
: d{std::exchange(other.d, nullptr)} {}
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QDirListing)
void swap(QDirListing &other) noexcept { qt_ptr_swap(d, other.d); }
Q_CORE_EXPORT ~QDirListing();
@ -137,7 +140,7 @@ private:
Q_CORE_EXPORT QDirListing(const QString &path, const QStringList &nameFilters, uint dirFilters,
uint qdirIteratorFlags = 0); // QDirIterator::NoIteratorFlags == 0x0
std::unique_ptr<QDirListingPrivate> d;
QDirListingPrivate *d;
friend class QDir;
friend class QDirPrivate;
friend class QDirIteratorPrivate;