From af50ec087e44a9102f4e66e7fed4385c108aced3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 6 May 2022 18:37:16 +0200 Subject: 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 --- src/qml/qml/ftw/qbipointer_p.h | 7 +++---- src/qml/qml/ftw/qqmlrefcount_p.h | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/qml') 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 &operator=(const QBiPointer &o) noexcept = default; QBiPointer &operator=(QBiPointer &&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 &ptr1, QBiPointer &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 &&); inline ~QQmlRefPointer(); + void swap(QQmlRefPointer &other) noexcept { qt_ptr_swap(o, other.o); } + inline QQmlRefPointer &operator=(const QQmlRefPointer &o); inline QQmlRefPointer &operator=(QQmlRefPointer &&o); @@ -198,7 +200,7 @@ template QQmlRefPointer &QQmlRefPointer::operator=(QQmlRefPointer &&other) { QQmlRefPointer m(std::move(other)); - qSwap(o, m.o); + swap(m); return *this; } -- cgit v1.2.3