From b1b0c2970e480ef460a61f37fa430dc443390358 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 19 Jan 2022 01:47:35 +0100 Subject: [PATCH] QtCore: replace qSwap with std::swap/member-swap where possible qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by providing a hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. Don't document it, otherwise we'd be unable to pick it to 6.2. Effects on Clang -ftime-trace of a PCH'ed libQt6Gui.so build: before: **** Template sets that took longest to instantiate: [...] 27766 ms: qSwap<$> (9073 times, avg 3 ms) [...] 2806 ms: std::swap<$> (1229 times, avg 2 ms) (30572ms) after: **** Template sets that took longest to instantiate: [...] 5047 ms: qSwap<$> (641 times, avg 7 ms) [...] 3371 ms: std::swap<$> (1376 times, avg 2 ms) [qt_ptr_swap<$> does not appear in the top 400, so < 905ms] (< 9323ms) As a drive-by, remove superfluous inline keywords and template ornaments. Task-number: QTBUG-97601 Pick-to: 6.3 6.2 Change-Id: I88f9b4e3cbece268c4a1238b6d50e5712a1bab5a Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann Reviewed-by: Fabian Kosmale Reviewed-by: Edward Welbourne --- src/corelib/global/qglobal.h | 9 +++++++++ src/corelib/io/qdebug.h | 2 +- src/corelib/io/qdir.h | 2 +- src/corelib/io/qfileinfo.h | 2 +- src/corelib/io/qprocess.h | 2 +- src/corelib/io/qstorageinfo.h | 2 +- src/corelib/io/qurl.h | 2 +- src/corelib/io/qurlquery.h | 2 +- src/corelib/itemmodels/qabstractitemmodel.h | 2 +- src/corelib/itemmodels/qitemselectionmodel.h | 4 ++-- src/corelib/kernel/qbasictimer.h | 2 +- src/corelib/kernel/qdeadlinetimer.h | 2 +- src/corelib/kernel/qobjectdefs.h | 2 +- src/corelib/kernel/qpropertyprivate.h | 2 +- src/corelib/mimetypes/qmimetype.h | 2 +- src/corelib/serialization/qcborarray.h | 2 +- src/corelib/serialization/qcbormap.h | 2 +- src/corelib/serialization/qcborvalue.h | 6 +++--- src/corelib/serialization/qjsonarray.h | 2 +- src/corelib/serialization/qjsonobject.h | 2 +- src/corelib/serialization/qxmlstream.h | 4 ++-- src/corelib/text/qbytearray.h | 6 +++--- src/corelib/text/qcollator.h | 2 +- src/corelib/text/qlocale.h | 2 +- src/corelib/text/qstring.h | 2 +- src/corelib/thread/qexception.h | 2 +- src/corelib/thread/qpromise.h | 2 +- src/corelib/thread/qsemaphore.h | 4 ++-- src/corelib/tools/qarraydatapointer.h | 6 +++--- src/corelib/tools/qbitarray.h | 2 +- src/corelib/tools/qcache.h | 4 ++-- src/corelib/tools/qcommandlineoption.h | 2 +- src/corelib/tools/qcontiguouscache.h | 2 +- src/corelib/tools/qeasingcurve.h | 2 +- src/corelib/tools/qhash.h | 9 +++++++-- src/corelib/tools/qlist.h | 2 +- src/corelib/tools/qmap.h | 4 ++-- src/corelib/tools/qscopedpointer.h | 2 +- src/corelib/tools/qshareddata.h | 4 ++-- src/corelib/tools/qshareddata_impl.h | 2 +- src/corelib/tools/qsharedpointer_impl.h | 12 ++++++------ src/corelib/tools/qtaggedpointer.h | 2 +- src/corelib/tools/qversionnumber.h | 2 +- 43 files changed, 74 insertions(+), 60 deletions(-) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index d686bbdb8a8..ad771d4f5fa 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1174,6 +1174,15 @@ constexpr void qSwap(T &value1, T &value2) swap(value1, value2); } +// pure compile-time micro-optimization for our own headers, so not documented: +template +constexpr inline void qt_ptr_swap(T* &lhs, T* &rhs) noexcept +{ + T *tmp = lhs; + lhs = rhs; + rhs = tmp; +} + QT_WARNING_POP Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1); diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index bfcdf42f0dc..2647f3da0f5 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -105,7 +105,7 @@ public: inline QDebug &operator=(const QDebug &other); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QDebug) ~QDebug(); - inline void swap(QDebug &other) noexcept { qSwap(stream, other.stream); } + void swap(QDebug &other) noexcept { qt_ptr_swap(stream, other.stream); } QDebug &resetFormat(); diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index 38a4d8d9616..7d7a483eae1 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -124,7 +124,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QDir) void swap(QDir &other) noexcept - { qSwap(d_ptr, other.d_ptr); } + { d_ptr.swap(other.d_ptr); } void setPath(const QString &path); #ifdef Q_CLANG_QDOC diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index 4bc5db9e2b8..b54a24e5637 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -91,7 +91,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFileInfo) void swap(QFileInfo &other) noexcept - { qSwap(d_ptr, other.d_ptr); } + { d_ptr.swap(other.d_ptr); } bool operator==(const QFileInfo &fileinfo) const; inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); } diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index 50740c092b2..97b586a2b4e 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -74,7 +74,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QProcessEnvironment) QProcessEnvironment &operator=(const QProcessEnvironment &other); - void swap(QProcessEnvironment &other) noexcept { qSwap(d, other.d); } + void swap(QProcessEnvironment &other) noexcept { d.swap(other.d); } bool operator==(const QProcessEnvironment &other) const; inline bool operator!=(const QProcessEnvironment &other) const diff --git a/src/corelib/io/qstorageinfo.h b/src/corelib/io/qstorageinfo.h index d441915a9ec..fc440fa05e6 100644 --- a/src/corelib/io/qstorageinfo.h +++ b/src/corelib/io/qstorageinfo.h @@ -65,7 +65,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QStorageInfo) inline void swap(QStorageInfo &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } void setPath(const QString &path); diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index 62b8e8cd931..3001904ef31 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -192,7 +192,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUrl) ~QUrl(); - inline void swap(QUrl &other) noexcept { qSwap(d, other.d); } + void swap(QUrl &other) noexcept { qt_ptr_swap(d, other.d); } void setUrl(const QString &url, ParsingMode mode = TolerantMode); QString url(FormattingOptions options = FormattingOptions(PrettyDecoded)) const; diff --git a/src/corelib/io/qurlquery.h b/src/corelib/io/qurlquery.h index aba5df6a579..e509f77cd2d 100644 --- a/src/corelib/io/qurlquery.h +++ b/src/corelib/io/qurlquery.h @@ -74,7 +74,7 @@ public: bool operator!=(const QUrlQuery &other) const { return !(*this == other); } - void swap(QUrlQuery &other) noexcept { qSwap(d, other.d); } + void swap(QUrlQuery &other) noexcept { d.swap(other.d); } bool isEmpty() const; bool isDetached() const; diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index a8d8a7de4bf..439e63a362f 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -222,7 +222,7 @@ public: inline QPersistentModelIndex(QPersistentModelIndex &&other) noexcept : d(qExchange(other.d, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPersistentModelIndex) - inline void swap(QPersistentModelIndex &other) noexcept { qSwap(d, other.d); } + void swap(QPersistentModelIndex &other) noexcept { qt_ptr_swap(d, other.d); } bool operator==(const QModelIndex &other) const; bool operator!=(const QModelIndex &other) const; QPersistentModelIndex &operator=(const QModelIndex &other); diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 678ba8bbad9..1d3fb0ec2a5 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -60,8 +60,8 @@ public: void swap(QItemSelectionRange &other) noexcept { - qSwap(tl, other.tl); - qSwap(br, other.br); + tl.swap(other.tl); + br.swap(other.br); } inline int top() const { return tl.row(); } diff --git a/src/corelib/kernel/qbasictimer.h b/src/corelib/kernel/qbasictimer.h index 6a2728dd56d..0d58964124f 100644 --- a/src/corelib/kernel/qbasictimer.h +++ b/src/corelib/kernel/qbasictimer.h @@ -63,7 +63,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QBasicTimer) - void swap(QBasicTimer &other) noexcept { qSwap(id, other.id); } + void swap(QBasicTimer &other) noexcept { std::swap(id, other.id); } bool isActive() const noexcept { return id != 0; } int timerId() const noexcept { return id; } diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index 08e80e448c8..0720a32b563 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -70,7 +70,7 @@ public: explicit QDeadlineTimer(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) noexcept; void swap(QDeadlineTimer &other) noexcept - { qSwap(t1, other.t1); qSwap(t2, other.t2); qSwap(type, other.type); } + { std::swap(t1, other.t1); std::swap(t2, other.t2); std::swap(type, other.type); } constexpr bool isForever() const noexcept { return t1 == (std::numeric_limits::max)(); } diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index 00a6b62eab3..6ffdb2a5de0 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -463,7 +463,7 @@ public: Connection(Connection &&other) noexcept : d_ptr(qExchange(other.d_ptr, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Connection) - void swap(Connection &other) noexcept { qSwap(d_ptr, other.d_ptr); } + void swap(Connection &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); } }; inline void swap(QMetaObject::Connection &lhs, QMetaObject::Connection &rhs) noexcept diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index 1c7f13046f6..8fe8cc7ff23 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -121,7 +121,7 @@ public: bool operator!() const noexcept { return d == nullptr; } void swap(QPropertyBindingPrivatePtr &other) noexcept - { qSwap(d, other.d); } + { qt_ptr_swap(d, other.d); } friend bool operator==(const QPropertyBindingPrivatePtr &p1, const QPropertyBindingPrivatePtr &p2) noexcept { return p1.d == p2.d; } diff --git a/src/corelib/mimetypes/qmimetype.h b/src/corelib/mimetypes/qmimetype.h index 365808e48b6..7424bcdf7a2 100644 --- a/src/corelib/mimetypes/qmimetype.h +++ b/src/corelib/mimetypes/qmimetype.h @@ -81,7 +81,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QMimeType) void swap(QMimeType &other) noexcept { - qSwap(d, other.d); + d.swap(other.d); } explicit QMimeType(const QMimeTypePrivate &dd); ~QMimeType(); diff --git a/src/corelib/serialization/qcborarray.h b/src/corelib/serialization/qcborarray.h index dd0628b3bb3..63f54dc2a5a 100644 --- a/src/corelib/serialization/qcborarray.h +++ b/src/corelib/serialization/qcborarray.h @@ -176,7 +176,7 @@ public: void swap(QCborArray &other) noexcept { - qSwap(d, other.d); + d.swap(other.d); } QCborValue toCborValue() const { return *this; } diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h index f84552d992f..ed9c2f21d58 100644 --- a/src/corelib/serialization/qcbormap.h +++ b/src/corelib/serialization/qcbormap.h @@ -178,7 +178,7 @@ public: void swap(QCborMap &other) noexcept { - qSwap(d, other.d); + d.swap(other.d); } QCborValue toCborValue() const { return *this; } diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index 9a26c9ab66e..6a1558e2b51 100644 --- a/src/corelib/serialization/qcborvalue.h +++ b/src/corelib/serialization/qcborvalue.h @@ -187,9 +187,9 @@ public: void swap(QCborValue &other) noexcept { - qSwap(n, other.n); - qSwap(container, other.container); - qSwap(t, other.t); + std::swap(n, other.n); + qt_ptr_swap(container, other.container); + std::swap(t, other.t); } Type type() const { return t; } diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h index 406fbc2f47d..462a7c76d8a 100644 --- a/src/corelib/serialization/qjsonarray.h +++ b/src/corelib/serialization/qjsonarray.h @@ -101,7 +101,7 @@ public: void swap(QJsonArray &other) noexcept { - qSwap(a, other.a); + a.swap(other.a); } class const_iterator; diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h index e4773456432..25912779ed7 100644 --- a/src/corelib/serialization/qjsonobject.h +++ b/src/corelib/serialization/qjsonobject.h @@ -74,7 +74,7 @@ public: void swap(QJsonObject &other) noexcept { - qSwap(o, other.o); + o.swap(other.o); } static QJsonObject fromVariantMap(const QVariantMap &map); diff --git a/src/corelib/serialization/qxmlstream.h b/src/corelib/serialization/qxmlstream.h index afd8563cc14..ed2da2e5135 100644 --- a/src/corelib/serialization/qxmlstream.h +++ b/src/corelib/serialization/qxmlstream.h @@ -58,12 +58,12 @@ public: QXmlString(QStringPrivate &&d) : m_string(std::move(d)) {} QXmlString(const QString &s) : m_string(s.data_ptr()) {} QXmlString & operator=(const QString &s) { m_string = s.data_ptr(); return *this; } - QXmlString & operator=(QString &&s) { qSwap(m_string, s.data_ptr()); return *this; } + QXmlString & operator=(QString &&s) { m_string.swap(s.data_ptr()); return *this; } inline constexpr QXmlString() {} void swap(QXmlString &other) noexcept { - qSwap(m_string, other.m_string); + m_string.swap(other.m_string); } inline operator QStringView() const { return QStringView(m_string.data(), m_string.size); } diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index dbbbd2f1788..d3b3c3ca6ec 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -124,7 +124,7 @@ public: { qSwap(d, other.d); } QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QByteArray) inline void swap(QByteArray &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } bool isEmpty() const noexcept { return size() == 0; } void resize(qsizetype size); @@ -629,8 +629,8 @@ public: void swap(QByteArray::FromBase64Result &other) noexcept { - qSwap(decoded, other.decoded); - qSwap(decodingStatus, other.decodingStatus); + decoded.swap(other.decoded); + std::swap(decodingStatus, other.decodingStatus); } explicit operator bool() const noexcept { return decodingStatus == QByteArray::Base64DecodingStatus::Ok; } diff --git a/src/corelib/text/qcollator.h b/src/corelib/text/qcollator.h index ddfbacfd197..a0333e6f071 100644 --- a/src/corelib/text/qcollator.h +++ b/src/corelib/text/qcollator.h @@ -87,7 +87,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCollator) void swap(QCollator &other) noexcept - { qSwap(d, other.d); } + { qt_ptr_swap(d, other.d); } void setLocale(const QLocale &locale); QLocale locale() const; diff --git a/src/corelib/text/qlocale.h b/src/corelib/text/qlocale.h index 0a583b08817..7f1d47063b3 100644 --- a/src/corelib/text/qlocale.h +++ b/src/corelib/text/qlocale.h @@ -938,7 +938,7 @@ public: QLocale &operator=(const QLocale &other); ~QLocale(); - void swap(QLocale &other) noexcept { qSwap(d, other.d); } + void swap(QLocale &other) noexcept { d.swap(other.d); } Language language() const; Script script() const; diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index cdf710e5d99..e886f1182b6 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -423,7 +423,7 @@ public: inline QString(QString &&other) noexcept { qSwap(d, other.d); } QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QString) - inline void swap(QString &other) noexcept { qSwap(d, other.d); } + void swap(QString &other) noexcept { d.swap(other.d); } inline qsizetype size() const { return d.size; } inline qsizetype count() const { return d.size; } inline qsizetype length() const { return d.size; } diff --git a/src/corelib/thread/qexception.h b/src/corelib/thread/qexception.h index 1c692876150..4d4d53304e6 100644 --- a/src/corelib/thread/qexception.h +++ b/src/corelib/thread/qexception.h @@ -72,7 +72,7 @@ public: QUnhandledException(QUnhandledException &&other) noexcept; QUnhandledException(const QUnhandledException &other) noexcept; - void swap(QUnhandledException &other) noexcept { qSwap(d, other.d); } + void swap(QUnhandledException &other) noexcept { d.swap(other.d); } QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUnhandledException) QUnhandledException &operator=(const QUnhandledException &other) noexcept; diff --git a/src/corelib/thread/qpromise.h b/src/corelib/thread/qpromise.h index 3cecbd83063..a970f40d126 100644 --- a/src/corelib/thread/qpromise.h +++ b/src/corelib/thread/qpromise.h @@ -106,7 +106,7 @@ public: void swap(QPromise &other) noexcept { - qSwap(this->d, other.d); + d.swap(other.d); } #if defined(Q_CLANG_QDOC) // documentation-only simplified signatures diff --git a/src/corelib/thread/qsemaphore.h b/src/corelib/thread/qsemaphore.h index b57a2741040..4e44965918e 100644 --- a/src/corelib/thread/qsemaphore.h +++ b/src/corelib/thread/qsemaphore.h @@ -109,8 +109,8 @@ public: void swap(QSemaphoreReleaser &other) noexcept { - qSwap(m_sem, other.m_sem); - qSwap(m_n, other.m_n); + qt_ptr_swap(m_sem, other.m_sem); + std::swap(m_n, other.m_n); } QSemaphore *semaphore() const noexcept diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index dda3cf13eb1..27598109198 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -149,9 +149,9 @@ public: void swap(QArrayDataPointer &other) noexcept { - qSwap(d, other.d); - qSwap(ptr, other.ptr); - qSwap(size, other.size); + qt_ptr_swap(d, other.d); + qt_ptr_swap(ptr, other.ptr); + std::swap(size, other.size); } void clear() noexcept(std::is_nothrow_destructible::value) diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h index 75d680dc84a..4466fbc9c05 100644 --- a/src/corelib/tools/qbitarray.h +++ b/src/corelib/tools/qbitarray.h @@ -62,7 +62,7 @@ public: inline QBitArray(QBitArray &&other) noexcept : d(std::move(other.d)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QBitArray) - inline void swap(QBitArray &other) noexcept { qSwap(d, other.d); } + void swap(QBitArray &other) noexcept { d.swap(other.d); } inline qsizetype size() const { return (d.size() << 3) - *d.constData(); } inline qsizetype count() const { return (d.size() << 3) - *d.constData(); } diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h index 72a456890fb..d5e978d6f37 100644 --- a/src/corelib/tools/qcache.h +++ b/src/corelib/tools/qcache.h @@ -64,8 +64,8 @@ class QCache } Value &operator=(Value &&other) noexcept { - qSwap(t, other.t); - qSwap(cost, other.cost); + qt_ptr_swap(t, other.t); + std::swap(cost, other.cost); return *this; } ~Value() { delete t; } diff --git a/src/corelib/tools/qcommandlineoption.h b/src/corelib/tools/qcommandlineoption.h index 2e7d8fd9da9..253c46a1784 100644 --- a/src/corelib/tools/qcommandlineoption.h +++ b/src/corelib/tools/qcommandlineoption.h @@ -75,7 +75,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QCommandLineOption) void swap(QCommandLineOption &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } QStringList names() const; diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index 62ebfa0658c..e78a4d3184d 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -97,7 +97,7 @@ public: QContiguousCache &operator=(const QContiguousCache &other); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QContiguousCache) - inline void swap(QContiguousCache &other) noexcept { qSwap(d, other.d); } + void swap(QContiguousCache &other) noexcept { qt_ptr_swap(d, other.d); } #ifndef Q_CLANG_QDOC template diff --git a/src/corelib/tools/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h index 7e50743bf12..225641d4775 100644 --- a/src/corelib/tools/qeasingcurve.h +++ b/src/corelib/tools/qeasingcurve.h @@ -81,7 +81,7 @@ public: QEasingCurve(QEasingCurve &&other) noexcept : d_ptr(other.d_ptr) { other.d_ptr = nullptr; } QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QEasingCurve) - void swap(QEasingCurve &other) noexcept { qSwap(d_ptr, other.d_ptr); } + void swap(QEasingCurve &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); } bool operator==(const QEasingCurve &other) const; inline bool operator!=(const QEasingCurve &other) const diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index c4b4098c0fa..a19713b337b 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -911,7 +911,7 @@ public: insert(f->first, f->second); } #endif - void swap(QHash &other) noexcept { qSwap(d, other.d); } + void swap(QHash &other) noexcept { qt_ptr_swap(d, other.d); } #ifndef Q_CLANG_QDOC template @@ -1446,7 +1446,12 @@ public: { unite(std::move(other)); } - void swap(QMultiHash &other) noexcept { qSwap(d, other.d); qSwap(m_size, other.m_size); } + + void swap(QMultiHash &other) noexcept + { + qt_ptr_swap(d, other.d); + std::swap(m_size, other.m_size); + } #ifndef Q_CLANG_QDOC template diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index aaa2a950dd9..93498dfa69b 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -351,7 +351,7 @@ public: // compiler-generated special member functions are fine! - void swap(QList &other) noexcept { qSwap(d, other.d); } + void swap(QList &other) noexcept { d.swap(other.d); } #ifndef Q_CLANG_QDOC template diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index f2f1bc96f40..5daf24189be 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -238,7 +238,7 @@ public: void swap(QMap &other) noexcept { - qSwap(d, other.d); + d.swap(other.d); } QMap(std::initializer_list> list) @@ -849,7 +849,7 @@ public: void swap(QMultiMap &other) noexcept { - qSwap(d, other.d); + d.swap(other.d); } explicit QMultiMap(const QMap &other) diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index c9afb248a18..8c7ecae01a9 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -173,7 +173,7 @@ public: QT_DEPRECATED_VERSION_X_6_2("Use std::unique_ptr instead of QScopedPointer.") void swap(QScopedPointer &other) noexcept { - qSwap(d, other.d); + qt_ptr_swap(d, other.d); } #endif diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index de11257db3e..717e33770e2 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -125,7 +125,7 @@ public: bool operator!() const noexcept { return d == nullptr; } void swap(QSharedDataPointer &other) noexcept - { qSwap(d, other.d); } + { qt_ptr_swap(d, other.d); } #define DECLARE_COMPARE_SET(T1, A1, T2, A2) \ friend bool operator<(T1, T2) noexcept \ @@ -222,7 +222,7 @@ public: bool operator!() const noexcept { return d == nullptr; } void swap(QExplicitlySharedDataPointer &other) noexcept - { qSwap(d, other.d); } + { qt_ptr_swap(d, other.d); } DECLARE_COMPARE_SET(const QExplicitlySharedDataPointer &p1, p1.d, const QExplicitlySharedDataPointer &p2, p2.d) DECLARE_COMPARE_SET(const QExplicitlySharedDataPointer &p1, p1.d, const T *ptr, ptr) diff --git a/src/corelib/tools/qshareddata_impl.h b/src/corelib/tools/qshareddata_impl.h index cf1c534cdf2..960dbdecdca 100644 --- a/src/corelib/tools/qshareddata_impl.h +++ b/src/corelib/tools/qshareddata_impl.h @@ -138,7 +138,7 @@ public: constexpr void swap(QExplicitlySharedDataPointerV2 &other) noexcept { - qSwap(d, other.d); + qt_ptr_swap(d, other.d); } // important change from QExplicitlySharedDataPointer: deep const diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 61aeee4952d..7b02ffe50ac 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -508,8 +508,8 @@ private: void internalSwap(QSharedPointer &other) noexcept { - qSwap(d, other.d); - qSwap(this->value, other.value); + qt_ptr_swap(d, other.d); + qt_ptr_swap(this->value, other.value); } template friend class QSharedPointer; @@ -538,8 +538,8 @@ private: } } - qSwap(d, o); - qSwap(this->value, actual); + qt_ptr_swap(d, o); + qt_ptr_swap(this->value, actual); if (!d || d->strongref.loadRelaxed() == 0) this->value = nullptr; @@ -609,8 +609,8 @@ public: void swap(QWeakPointer &other) noexcept { - qSwap(this->d, other.d); - qSwap(this->value, other.value); + qt_ptr_swap(this->d, other.d); + qt_ptr_swap(this->value, other.value); } inline QWeakPointer(const QSharedPointer &o) : d(o.d), value(o.data()) diff --git a/src/corelib/tools/qtaggedpointer.h b/src/corelib/tools/qtaggedpointer.h index c12d5acdc2f..68074cc43d8 100644 --- a/src/corelib/tools/qtaggedpointer.h +++ b/src/corelib/tools/qtaggedpointer.h @@ -144,7 +144,7 @@ public: void swap(QTaggedPointer &other) noexcept { - qSwap(d, other.d); + std::swap(d, other.d); } friend inline bool operator==(QTaggedPointer lhs, QTaggedPointer rhs) noexcept diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index 7b3e0995a05..8efdde33913 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -131,7 +131,7 @@ class QVersionNumber void swap(SegmentStorage &other) noexcept { - qSwap(dummy, other.dummy); + std::swap(dummy, other.dummy); } explicit SegmentStorage(QList &&seg)