Copy or check ShortData rather than pointer in more places

This follows-up on commit 4d24fcd3e1dce6c56d9fc70ee386dcc8aa552ef6 -
when ShortData is bigger than a pointer (on 32-bit systems, when using
64-bit ShortData), copying d isn't sufficient; data must be copied.
Likewise, comparing d to check for equality is insufficient when
isShort(), as the other may also be short and differ in the more
significant bytes.

Change-Id: I49c0cf33727b8b43436cf0e3f57f602e83226885
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2022-08-26 10:02:39 +02:00
parent 1bc7e9e77b
commit c88d2b0fcd
2 changed files with 6 additions and 4 deletions

View File

@ -3016,7 +3016,7 @@ inline QDateTime::Data::Data(Qt::TimeSpec spec)
} }
inline QDateTime::Data::Data(const Data &other) noexcept inline QDateTime::Data::Data(const Data &other) noexcept
: d(other.d) : data(other.data)
{ {
if (!isShort()) { if (!isShort()) {
// check if we could shrink // check if we could shrink
@ -3033,17 +3033,17 @@ inline QDateTime::Data::Data(const Data &other) noexcept
} }
inline QDateTime::Data::Data(Data &&other) noexcept inline QDateTime::Data::Data(Data &&other) noexcept
: d(other.d) : data(other.data)
{ {
// reset the other to a short state // reset the other to a short state
Data dummy; Data dummy;
Q_ASSERT(dummy.isShort()); Q_ASSERT(dummy.isShort());
other.d = dummy.d; other.data = dummy.data;
} }
inline QDateTime::Data &QDateTime::Data::operator=(const Data &other) noexcept inline QDateTime::Data &QDateTime::Data::operator=(const Data &other) noexcept
{ {
if (d == other.d) if (isShort() ? data == other.data : d == other.d)
return *this; return *this;
auto x = d; auto x = d;

View File

@ -266,6 +266,8 @@ class Q_CORE_EXPORT QDateTime
#if Q_BYTE_ORDER == Q_BIG_ENDIAN #if Q_BYTE_ORDER == Q_BIG_ENDIAN
quintptr status : 8; quintptr status : 8;
#endif #endif
friend constexpr bool operator==(const ShortData &lhs, const ShortData &rhs)
{ return lhs.status == rhs.status && lhs.msecs == rhs.msecs; }
}; };
union Data { union Data {