summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qmap.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-19 01:47:35 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-20 22:56:12 +0100
commitb1b0c2970e480ef460a61f37fa430dc443390358 (patch)
tree3f4045199a8e82a7d39b1f4b9b6055fd8b69ef6f /src/corelib/tools/qmap.h
parentb083c27d0ab1e436c1b21785c67e2df419c67335 (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/qmap.h')
-rw-r--r--src/corelib/tools/qmap.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index f2f1bc96f4..5daf24189b 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -238,7 +238,7 @@ public:
void swap(QMap<Key, T> &other) noexcept
{
- qSwap(d, other.d);
+ d.swap(other.d);
}
QMap(std::initializer_list<std::pair<Key, T>> list)
@@ -849,7 +849,7 @@ public:
void swap(QMultiMap<Key, T> &other) noexcept
{
- qSwap(d, other.d);
+ d.swap(other.d);
}
explicit QMultiMap(const QMap<Key, T> &other)