Add move constructor to QDateTime
The move constructor is slightly more interesting than the copy
constructor because we can reset other to a short data state on 64-bit
systems. The assembly of that function is simply:
mov (%rsi),%rax
mov %rax,(%rdi)
movq $0x1,(%rsi)
retq
The move-assignment operator for QDateTime was already there. There's no
need for one for QDateTime::Data since it's never called.
Change-Id: I06bae9392f534e45b3f1ffff144dffdd7f23b170
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
parent
72393ac3b6
commit
cbe62a0e6d
|
|
@ -2763,6 +2763,20 @@ inline QDateTime::Data::Data(const Data &other)
|
|||
}
|
||||
}
|
||||
|
||||
inline QDateTime::Data::Data(Data &&other)
|
||||
: d(other.d)
|
||||
{
|
||||
// reset the other to a short state, if we can
|
||||
if (CanBeSmall) {
|
||||
Data dummy(Qt::LocalTime);
|
||||
Q_ASSERT(dummy.isShort());
|
||||
other.d = dummy.d;
|
||||
} else if (!isShort()) {
|
||||
// can't be small, so do implicit sharing
|
||||
d->ref.ref();
|
||||
}
|
||||
}
|
||||
|
||||
inline QDateTime::Data &QDateTime::Data::operator=(const Data &other)
|
||||
{
|
||||
if (d == other.d)
|
||||
|
|
@ -3095,12 +3109,21 @@ QDateTime::QDateTime(const QDate &date, const QTime &time, const QTimeZone &time
|
|||
/*!
|
||||
Constructs a copy of the \a other datetime.
|
||||
*/
|
||||
|
||||
QDateTime::QDateTime(const QDateTime &other) Q_DECL_NOTHROW
|
||||
: d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.8
|
||||
Moves the content of the temporary \a other datetime to this object and
|
||||
leaves \a other in an unspecified (but proper) state.
|
||||
*/
|
||||
QDateTime::QDateTime(QDateTime &&other) Q_DECL_NOTHROW
|
||||
: d(std::move(other.d))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
Destroys the datetime.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -232,8 +232,8 @@ class Q_CORE_EXPORT QDateTime
|
|||
|
||||
Data(Qt::TimeSpec);
|
||||
Data(const Data &other);
|
||||
Data(Data &&other);
|
||||
Data &operator=(const Data &other);
|
||||
// no move semantics (would be the same as copy)
|
||||
~Data();
|
||||
|
||||
bool isShort() const;
|
||||
|
|
@ -256,6 +256,7 @@ public:
|
|||
QDateTime(const QDate &date, const QTime &time, const QTimeZone &timeZone);
|
||||
#endif // QT_BOOTSTRAPPED
|
||||
QDateTime(const QDateTime &other) Q_DECL_NOTHROW;
|
||||
QDateTime(QDateTime &&other) Q_DECL_NOTHROW;
|
||||
~QDateTime();
|
||||
|
||||
#ifdef Q_COMPILER_RVALUE_REFS
|
||||
|
|
|
|||
Loading…
Reference in New Issue