summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-07-08 14:33:15 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-07-18 12:05:28 +0200
commit8abef0277797724b153cb08c11bf498efc6d460d (patch)
tree00641d53530a2f3d0b59a2d2aaf1cc4913b0e883 /src/network/kernel
parentc187d5824487b1d5f04bc504c04608c562922d4a (diff)
QHostInfo: add nothrow move constructor
QHostInfo isn't implicitly shared. The more important to optimize away copies by providing a move constructor. Port from QScopedPointer to Q_DECLARE_PRIVATE, as otherwise the move ctor can't be inline, and we don't implement move ctors out-of-line in Qt. [ChangeLog][QtNetwork][QHostInfo] Added move contructor. Change-Id: I6b63a04e36f63e299205830fdc590ff7e2af338b Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qhostinfo.cpp31
-rw-r--r--src/network/kernel/qhostinfo.h6
2 files changed, 32 insertions, 5 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index c17ba38e36..a5e50ff21b 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -594,8 +594,9 @@ QHostInfo QHostInfoAgent::lookup(const QString &hostName)
\sa lookupId()
*/
QHostInfo::QHostInfo(int id)
- : d(new QHostInfoPrivate)
+ : d_ptr(new QHostInfoPrivate)
{
+ Q_D(QHostInfo);
d->lookupId = id;
}
@@ -603,17 +604,30 @@ QHostInfo::QHostInfo(int id)
Constructs a copy of \a other.
*/
QHostInfo::QHostInfo(const QHostInfo &other)
- : d(new QHostInfoPrivate(*other.d.data()))
+ : d_ptr(new QHostInfoPrivate(*other.d_ptr))
{
}
/*!
+ Move-constucts a new QHostInfo from \a other.
+
+ \note The moved-from object \a other is placed in a
+ partially-formed state, in which the only valid operations are
+ destruction and assignment of a new value.
+
+ \since 5.14
+*/
+
+/*!
Assigns the data of the \a other object to this host info object,
and returns a reference to it.
*/
QHostInfo &QHostInfo::operator=(const QHostInfo &other)
{
- *d.data() = *other.d.data();
+ if (d_ptr)
+ *d_ptr = *other.d_ptr;
+ else
+ d_ptr = new QHostInfoPrivate(*other.d_ptr);
return *this;
}
@@ -622,6 +636,7 @@ QHostInfo &QHostInfo::operator=(const QHostInfo &other)
*/
QHostInfo::~QHostInfo()
{
+ delete d_ptr;
}
/*!
@@ -636,6 +651,7 @@ QHostInfo::~QHostInfo()
*/
QList<QHostAddress> QHostInfo::addresses() const
{
+ Q_D(const QHostInfo);
return d->addrs;
}
@@ -646,6 +662,7 @@ QList<QHostAddress> QHostInfo::addresses() const
*/
void QHostInfo::setAddresses(const QList<QHostAddress> &addresses)
{
+ Q_D(QHostInfo);
d->addrs = addresses;
}
@@ -656,6 +673,7 @@ void QHostInfo::setAddresses(const QList<QHostAddress> &addresses)
*/
QString QHostInfo::hostName() const
{
+ Q_D(const QHostInfo);
return d->hostName;
}
@@ -666,6 +684,7 @@ QString QHostInfo::hostName() const
*/
void QHostInfo::setHostName(const QString &hostName)
{
+ Q_D(QHostInfo);
d->hostName = hostName;
}
@@ -677,6 +696,7 @@ void QHostInfo::setHostName(const QString &hostName)
*/
QHostInfo::HostInfoError QHostInfo::error() const
{
+ Q_D(const QHostInfo);
return d->err;
}
@@ -687,6 +707,7 @@ QHostInfo::HostInfoError QHostInfo::error() const
*/
void QHostInfo::setError(HostInfoError error)
{
+ Q_D(QHostInfo);
d->err = error;
}
@@ -697,6 +718,7 @@ void QHostInfo::setError(HostInfoError error)
*/
int QHostInfo::lookupId() const
{
+ Q_D(const QHostInfo);
return d->lookupId;
}
@@ -707,6 +729,7 @@ int QHostInfo::lookupId() const
*/
void QHostInfo::setLookupId(int id)
{
+ Q_D(QHostInfo);
d->lookupId = id;
}
@@ -718,6 +741,7 @@ void QHostInfo::setLookupId(int id)
*/
QString QHostInfo::errorString() const
{
+ Q_D(const QHostInfo);
return d->errorStr;
}
@@ -729,6 +753,7 @@ QString QHostInfo::errorString() const
*/
void QHostInfo::setErrorString(const QString &str)
{
+ Q_D(QHostInfo);
d->errorStr = str;
}
diff --git a/src/network/kernel/qhostinfo.h b/src/network/kernel/qhostinfo.h
index dc31cc08e4..cda286b423 100644
--- a/src/network/kernel/qhostinfo.h
+++ b/src/network/kernel/qhostinfo.h
@@ -62,11 +62,12 @@ public:
explicit QHostInfo(int lookupId = -1);
QHostInfo(const QHostInfo &d);
+ QHostInfo(QHostInfo &&other) noexcept : d_ptr(qExchange(other.d_ptr, nullptr)) {}
QHostInfo &operator=(const QHostInfo &d);
QHostInfo &operator=(QHostInfo &&other) noexcept { swap(other); return *this; }
~QHostInfo();
- void swap(QHostInfo &other) noexcept { qSwap(d, other.d); }
+ void swap(QHostInfo &other) noexcept { qSwap(d_ptr, other.d_ptr); }
QString hostName() const;
void setHostName(const QString &name);
@@ -147,7 +148,8 @@ public:
#endif // Q_QDOC
private:
- QScopedPointer<QHostInfoPrivate> d;
+ QHostInfoPrivate *d_ptr;
+ Q_DECLARE_PRIVATE(QHostInfo)
static int lookupHostImpl(const QString &name,
const QObject *receiver,