diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-01-19 01:47:35 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-01-20 22:56:12 +0100 |
commit | b1b0c2970e480ef460a61f37fa430dc443390358 (patch) | |
tree | 3f4045199a8e82a7d39b1f4b9b6055fd8b69ef6f /src/corelib/tools/qarraydatapointer.h | |
parent | b083c27d0ab1e436c1b21785c67e2df419c67335 (diff) |
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 <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydatapointer.h')
-rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index dda3cf13eb..2759810919 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<T>::value) |