QtNetwork: compile-optimize inline swap functions

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. b1b0c2970e.

Pick-to: 6.3 6.2
Task-number: QTBUG-97601
Change-Id: I26586da1f158fe6b18314abd8cf9bb040bc9cad1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2022-03-15 21:20:46 +01:00
parent 870bb22c17
commit f438d29b6f
17 changed files with 23 additions and 23 deletions

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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); }

View File

@ -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;

View File

@ -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); }

View File

@ -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

View File

@ -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);

View File

@ -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; }

View File

@ -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();

View File

@ -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;