From 7e5229aa535c362ea44db1590d83274e26c1ded3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 15 Mar 2022 21:20:46 +0100 Subject: QtNetwork: compile-optimize inline swap functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of using the overly-generic qSwap() monster, use - qt_ptr_swap() for swapping raw pointers - member-swap for swapping smart pointers - std::swap() for swapping scalars In QtCore, this has proven to give a nice reduction in compile time for Qt users, cf. b1b0c2970e480ef460a61f37fa430dc443390358. Task-number: QTBUG-97601 Change-Id: I26586da1f158fe6b18314abd8cf9bb040bc9cad1 Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit f438d29b6fdfff0680b09e88590ee47b22877776) Reviewed-by: Qt Cherry-pick Bot --- src/network/access/qhstspolicy.h | 2 +- src/network/access/qhttpmultipart.h | 2 +- src/network/access/qnetworkcookie.h | 2 +- src/network/access/qnetworkrequest.h | 2 +- src/network/kernel/qdnslookup.h | 10 +++++----- src/network/kernel/qhostinfo.h | 2 +- src/network/kernel/qnetworkdatagram.h | 2 +- src/network/kernel/qnetworkinterface.h | 4 ++-- src/network/kernel/qnetworkproxy.h | 4 ++-- src/network/ssl/qsslcertificate.h | 2 +- src/network/ssl/qsslcertificateextension.h | 2 +- src/network/ssl/qsslcipher.h | 2 +- src/network/ssl/qsslconfiguration.h | 2 +- src/network/ssl/qssldiffiehellmanparameters.h | 2 +- src/network/ssl/qsslerror.h | 2 +- src/network/ssl/qsslkey.h | 2 +- src/network/ssl/qsslpresharedkeyauthenticator.h | 2 +- 17 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/network/access/qhstspolicy.h b/src/network/access/qhstspolicy.h index 0cf0c73f9c..12bb25c19d 100644 --- a/src/network/access/qhstspolicy.h +++ b/src/network/access/qhstspolicy.h @@ -68,7 +68,7 @@ public: QHstsPolicy &operator=(QHstsPolicy &&other) noexcept { swap(other); return *this; } ~QHstsPolicy(); - void swap(QHstsPolicy &other) noexcept { qSwap(d, other.d); } + void swap(QHstsPolicy &other) noexcept { d.swap(other.d); } void setHost(const QString &host, QUrl::ParsingMode mode = QUrl::DecodedMode); QString host(QUrl::ComponentFormattingOptions options = QUrl::FullyDecoded) const; diff --git a/src/network/access/qhttpmultipart.h b/src/network/access/qhttpmultipart.h index 7f07008c0f..90d3a8bf1b 100644 --- a/src/network/access/qhttpmultipart.h +++ b/src/network/access/qhttpmultipart.h @@ -65,7 +65,7 @@ public: QHttpPart &operator=(QHttpPart &&other) noexcept { swap(other); return *this; } QHttpPart &operator=(const QHttpPart &other); - void swap(QHttpPart &other) noexcept { qSwap(d, other.d); } + void swap(QHttpPart &other) noexcept { d.swap(other.d); } bool operator==(const QHttpPart &other) const; inline bool operator!=(const QHttpPart &other) const diff --git a/src/network/access/qnetworkcookie.h b/src/network/access/qnetworkcookie.h index 265f3a7124..dfb5f7c14d 100644 --- a/src/network/access/qnetworkcookie.h +++ b/src/network/access/qnetworkcookie.h @@ -77,7 +77,7 @@ public: QNetworkCookie &operator=(QNetworkCookie &&other) noexcept { swap(other); return *this; } QNetworkCookie &operator=(const QNetworkCookie &other); - void swap(QNetworkCookie &other) noexcept { qSwap(d, other.d); } + void swap(QNetworkCookie &other) noexcept { d.swap(other.d); } bool operator==(const QNetworkCookie &other) const; inline bool operator!=(const QNetworkCookie &other) const diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index 5d5ae292c8..c797b853c4 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -138,7 +138,7 @@ public: QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; } QNetworkRequest &operator=(const QNetworkRequest &other); - void swap(QNetworkRequest &other) noexcept { qSwap(d, other.d); } + void swap(QNetworkRequest &other) noexcept { d.swap(other.d); } bool operator==(const QNetworkRequest &other) const; inline bool operator!=(const QNetworkRequest &other) const diff --git a/src/network/kernel/qdnslookup.h b/src/network/kernel/qdnslookup.h index 89d617a92e..350e6ff67f 100644 --- a/src/network/kernel/qdnslookup.h +++ b/src/network/kernel/qdnslookup.h @@ -69,7 +69,7 @@ public: QDnsDomainNameRecord &operator=(const QDnsDomainNameRecord &other); ~QDnsDomainNameRecord(); - void swap(QDnsDomainNameRecord &other) noexcept { qSwap(d, other.d); } + void swap(QDnsDomainNameRecord &other) noexcept { d.swap(other.d); } QString name() const; quint32 timeToLive() const; @@ -91,7 +91,7 @@ public: QDnsHostAddressRecord &operator=(const QDnsHostAddressRecord &other); ~QDnsHostAddressRecord(); - void swap(QDnsHostAddressRecord &other) noexcept { qSwap(d, other.d); } + void swap(QDnsHostAddressRecord &other) noexcept { d.swap(other.d); } QString name() const; quint32 timeToLive() const; @@ -113,7 +113,7 @@ public: QDnsMailExchangeRecord &operator=(const QDnsMailExchangeRecord &other); ~QDnsMailExchangeRecord(); - void swap(QDnsMailExchangeRecord &other) noexcept { qSwap(d, other.d); } + void swap(QDnsMailExchangeRecord &other) noexcept { d.swap(other.d); } QString exchange() const; QString name() const; @@ -136,7 +136,7 @@ public: QDnsServiceRecord &operator=(const QDnsServiceRecord &other); ~QDnsServiceRecord(); - void swap(QDnsServiceRecord &other) noexcept { qSwap(d, other.d); } + void swap(QDnsServiceRecord &other) noexcept { d.swap(other.d); } QString name() const; quint16 port() const; @@ -161,7 +161,7 @@ public: QDnsTextRecord &operator=(const QDnsTextRecord &other); ~QDnsTextRecord(); - void swap(QDnsTextRecord &other) noexcept { qSwap(d, other.d); } + void swap(QDnsTextRecord &other) noexcept { d.swap(other.d); } QString name() const; quint32 timeToLive() const; diff --git a/src/network/kernel/qhostinfo.h b/src/network/kernel/qhostinfo.h index fd1567eb07..ecab6360e8 100644 --- a/src/network/kernel/qhostinfo.h +++ b/src/network/kernel/qhostinfo.h @@ -67,7 +67,7 @@ public: QHostInfo &operator=(QHostInfo &&other) noexcept { swap(other); return *this; } ~QHostInfo(); - void swap(QHostInfo &other) noexcept { qSwap(d_ptr, other.d_ptr); } + void swap(QHostInfo &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); } QString hostName() const; void setHostName(const QString &name); diff --git a/src/network/kernel/qnetworkdatagram.h b/src/network/kernel/qnetworkdatagram.h index 70958fea42..2b4facecff 100644 --- a/src/network/kernel/qnetworkdatagram.h +++ b/src/network/kernel/qnetworkdatagram.h @@ -68,7 +68,7 @@ public: { swap(other); return *this; } void swap(QNetworkDatagram &other) noexcept - { qSwap(d, other.d); } + { qt_ptr_swap(d, other.d); } void clear(); bool isValid() const; diff --git a/src/network/kernel/qnetworkinterface.h b/src/network/kernel/qnetworkinterface.h index ef4dce1c01..34e2929092 100644 --- a/src/network/kernel/qnetworkinterface.h +++ b/src/network/kernel/qnetworkinterface.h @@ -69,7 +69,7 @@ public: QNetworkAddressEntry &operator=(const QNetworkAddressEntry &other); ~QNetworkAddressEntry(); - void swap(QNetworkAddressEntry &other) noexcept { qSwap(d, other.d); } + void swap(QNetworkAddressEntry &other) noexcept { d.swap(other.d); } bool operator==(const QNetworkAddressEntry &other) const; inline bool operator!=(const QNetworkAddressEntry &other) const @@ -146,7 +146,7 @@ public: QNetworkInterface &operator=(const QNetworkInterface &other); ~QNetworkInterface(); - void swap(QNetworkInterface &other) noexcept { qSwap(d, other.d); } + void swap(QNetworkInterface &other) noexcept { d.swap(other.d); } bool isValid() const; diff --git a/src/network/kernel/qnetworkproxy.h b/src/network/kernel/qnetworkproxy.h index 1f0409e8ab..bf5af82064 100644 --- a/src/network/kernel/qnetworkproxy.h +++ b/src/network/kernel/qnetworkproxy.h @@ -79,7 +79,7 @@ public: QNetworkProxyQuery &operator=(const QNetworkProxyQuery &other); ~QNetworkProxyQuery(); - void swap(QNetworkProxyQuery &other) noexcept { qSwap(d, other.d); } + void swap(QNetworkProxyQuery &other) noexcept { d.swap(other.d); } bool operator==(const QNetworkProxyQuery &other) const; inline bool operator!=(const QNetworkProxyQuery &other) const @@ -142,7 +142,7 @@ public: QNetworkProxy &operator=(const QNetworkProxy &other); ~QNetworkProxy(); - void swap(QNetworkProxy &other) noexcept { qSwap(d, other.d); } + void swap(QNetworkProxy &other) noexcept { d.swap(other.d); } bool operator==(const QNetworkProxy &other) const; inline bool operator!=(const QNetworkProxy &other) const diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h index e8349d502b..94e784745b 100644 --- a/src/network/ssl/qsslcertificate.h +++ b/src/network/ssl/qsslcertificate.h @@ -97,7 +97,7 @@ public: QSslCertificate &operator=(const QSslCertificate &other); void swap(QSslCertificate &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } bool operator==(const QSslCertificate &other) const; inline bool operator!=(const QSslCertificate &other) const { return !operator==(other); } diff --git a/src/network/ssl/qsslcertificateextension.h b/src/network/ssl/qsslcertificateextension.h index 7cc8a888be..70a1108f95 100644 --- a/src/network/ssl/qsslcertificateextension.h +++ b/src/network/ssl/qsslcertificateextension.h @@ -59,7 +59,7 @@ public: QSslCertificateExtension &operator=(const QSslCertificateExtension &other); ~QSslCertificateExtension(); - void swap(QSslCertificateExtension &other) noexcept { qSwap(d, other.d); } + void swap(QSslCertificateExtension &other) noexcept { d.swap(other.d); } QString oid() const; QString name() const; diff --git a/src/network/ssl/qsslcipher.h b/src/network/ssl/qsslcipher.h index bc54b1cf91..6d7aa592b5 100644 --- a/src/network/ssl/qsslcipher.h +++ b/src/network/ssl/qsslcipher.h @@ -66,7 +66,7 @@ public: ~QSslCipher(); void swap(QSslCipher &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } bool operator==(const QSslCipher &other) const; inline bool operator!=(const QSslCipher &other) const { return !operator==(other); } diff --git a/src/network/ssl/qsslconfiguration.h b/src/network/ssl/qsslconfiguration.h index 43566bc0cd..f88110f5a9 100644 --- a/src/network/ssl/qsslconfiguration.h +++ b/src/network/ssl/qsslconfiguration.h @@ -83,7 +83,7 @@ public: QSslConfiguration &operator=(const QSslConfiguration &other); void swap(QSslConfiguration &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } bool operator==(const QSslConfiguration &other) const; inline bool operator!=(const QSslConfiguration &other) const diff --git a/src/network/ssl/qssldiffiehellmanparameters.h b/src/network/ssl/qssldiffiehellmanparameters.h index c65697796b..9121c7bf64 100644 --- a/src/network/ssl/qssldiffiehellmanparameters.h +++ b/src/network/ssl/qssldiffiehellmanparameters.h @@ -82,7 +82,7 @@ public: QSslDiffieHellmanParameters &operator=(const QSslDiffieHellmanParameters &other); QSslDiffieHellmanParameters &operator=(QSslDiffieHellmanParameters &&other) noexcept { swap(other); return *this; } - void swap(QSslDiffieHellmanParameters &other) noexcept { qSwap(d, other.d); } + void swap(QSslDiffieHellmanParameters &other) noexcept { qt_ptr_swap(d, other.d); } static QSslDiffieHellmanParameters fromEncoded(const QByteArray &encoded, QSsl::EncodingFormat format = QSsl::Pem); static QSslDiffieHellmanParameters fromEncoded(QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem); diff --git a/src/network/ssl/qsslerror.h b/src/network/ssl/qsslerror.h index a5865a5a33..326e35301c 100644 --- a/src/network/ssl/qsslerror.h +++ b/src/network/ssl/qsslerror.h @@ -108,7 +108,7 @@ public: QSslError(const QSslError &other); void swap(QSslError &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } ~QSslError(); QSslError &operator=(QSslError &&other) noexcept { swap(other); return *this; } diff --git a/src/network/ssl/qsslkey.h b/src/network/ssl/qsslkey.h index d9df2686e6..350829a572 100644 --- a/src/network/ssl/qsslkey.h +++ b/src/network/ssl/qsslkey.h @@ -74,7 +74,7 @@ public: QSslKey &operator=(const QSslKey &other); ~QSslKey(); - void swap(QSslKey &other) noexcept { qSwap(d, other.d); } + void swap(QSslKey &other) noexcept { d.swap(other.d); } bool isNull() const; void clear(); diff --git a/src/network/ssl/qsslpresharedkeyauthenticator.h b/src/network/ssl/qsslpresharedkeyauthenticator.h index 41112e3e43..56c0e25900 100644 --- a/src/network/ssl/qsslpresharedkeyauthenticator.h +++ b/src/network/ssl/qsslpresharedkeyauthenticator.h @@ -60,7 +60,7 @@ public: QSslPreSharedKeyAuthenticator &operator=(QSslPreSharedKeyAuthenticator &&other) noexcept { swap(other); return *this; } - void swap(QSslPreSharedKeyAuthenticator &other) noexcept { qSwap(d, other.d); } + void swap(QSslPreSharedKeyAuthenticator &other) noexcept { d.swap(other.d); } Q_NETWORK_EXPORT QByteArray identityHint() const; -- cgit v1.2.3