summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
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/text
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/text')
-rw-r--r--src/corelib/text/qbytearray.h6
-rw-r--r--src/corelib/text/qcollator.h2
-rw-r--r--src/corelib/text/qlocale.h2
-rw-r--r--src/corelib/text/qstring.h2
4 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h
index dbbbd2f178..d3b3c3ca6e 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 ddfbacfd19..a0333e6f07 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 0a583b0881..7f1d47063b 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 cdf710e5d9..e886f1182b 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; }