aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-06 18:37:16 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-05-07 23:19:05 +0200
commitaf50ec087e44a9102f4e66e7fed4385c108aced3 (patch)
tree26e295b2d1fa8125f0129e5033a7903f2a24e17a /src/qml
parentcc49e68bdf5be947cd9a6aac07bc9915fe0c5af4 (diff)
QBiPointer/QQmlRefPointer: add member-swap, don't use qSwap
All types that have a swap() overload should also define a member-swap, and the ADL swap should call the member-swap. This minimizes the work the compiler has to do to find a fitting swap overload and experience shows that directly translates into compilation speedups. For the same reason, don't use qSwap(). It's 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. Pick-to: 6.3 6.2 5.15 Task-number: QTBUG-97601 Change-Id: I4d390a8b51c97d025989c1ad8786cc37f26438c8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/qml/ftw/qbipointer_p.h7
-rw-r--r--src/qml/qml/ftw/qqmlrefcount_p.h4
2 files changed, 6 insertions, 5 deletions
diff --git a/src/qml/qml/ftw/qbipointer_p.h b/src/qml/qml/ftw/qbipointer_p.h
index db272d41f8..24b4335367 100644
--- a/src/qml/qml/ftw/qbipointer_p.h
+++ b/src/qml/qml/ftw/qbipointer_p.h
@@ -86,6 +86,8 @@ public:
QBiPointer<T, T2> &operator=(const QBiPointer<T, T2> &o) noexcept = default;
QBiPointer<T, T2> &operator=(QBiPointer<T, T2> &&o) noexcept = default;
+ void swap(QBiPointer &other) noexcept { std::swap(ptr_value, other.ptr_value); }
+
inline QBiPointer(T *);
inline QBiPointer(T2 *);
@@ -116,10 +118,7 @@ public:
return !(ptr1 == ptr2);
}
- friend inline void swap(QBiPointer<T, T2> &ptr1, QBiPointer<T, T2> &ptr2) noexcept
- {
- qSwap(ptr1.ptr_value, ptr2.ptr_value);
- }
+ friend void swap(QBiPointer &lhs, QBiPointer &rhs) noexcept { lhs.swap(rhs); }
inline T *asT1() const;
inline T2 *asT2() const;
diff --git a/src/qml/qml/ftw/qqmlrefcount_p.h b/src/qml/qml/ftw/qqmlrefcount_p.h
index cb0374d8b6..bb0b0ba2a6 100644
--- a/src/qml/qml/ftw/qqmlrefcount_p.h
+++ b/src/qml/qml/ftw/qqmlrefcount_p.h
@@ -88,6 +88,8 @@ public:
inline QQmlRefPointer(QQmlRefPointer<T> &&);
inline ~QQmlRefPointer();
+ void swap(QQmlRefPointer &other) noexcept { qt_ptr_swap(o, other.o); }
+
inline QQmlRefPointer<T> &operator=(const QQmlRefPointer<T> &o);
inline QQmlRefPointer<T> &operator=(QQmlRefPointer<T> &&o);
@@ -198,7 +200,7 @@ template <class T>
QQmlRefPointer<T> &QQmlRefPointer<T>::operator=(QQmlRefPointer<T> &&other)
{
QQmlRefPointer<T> m(std::move(other));
- qSwap(o, m.o);
+ swap(m);
return *this;
}