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>bb10
parent
c187d58244
commit
8abef02777
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue