Remove QUuid(quint128) constructor again

This constructor matches way too many argument types (integral,
unscoped enums, FP types), so it's likely to cause mayhem, even if
left in as an explicit constructor.

We now have a named constructor for the same functionality, so just
drop the "unnamed" constructor.

"Unnamed" constructors are important when emplacement is more
efficient than construction + move, or when implicit conversion is
required.  Neither is the case here: The named as well as the
"unnamed" constructors just copy ten bytes around, and the compiler
can optimize those extra copies away just fine.

Found in API review.

Pick-to: 6.6
Change-Id: I7faafd3ebf522fb2b0e450112fb95d643fece5ce
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Marc Mutz 2023-08-10 16:03:46 +02:00 committed by Thiago Macieira
parent 3693dd74fe
commit 9c1d20337a
3 changed files with 14 additions and 28 deletions

View File

@ -310,19 +310,6 @@ static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCrypto
\sa fromBytes(), toBytes(), toRfc4122(), toUInt128() \sa fromBytes(), toBytes(), toRfc4122(), toUInt128()
*/ */
/*!
\fn QUuid::QUuid(quint128 uuid, QSysInfo::Endian order) noexcept
\since 6.6
Creates a QUuid based on the integral \a uuid parameter and respecting the
byte order \a order.
\note This function is only present on platforms that offer a 128-bit
integer type.
\sa toUInt128(), fromUInt128(), fromBytes(), toBytes(), toRfc4122()
*/
/*! /*!
\fn QUuid::fromUInt128(quint128 uuid, QSysInfo::Endian order) noexcept \fn QUuid::fromUInt128(quint128 uuid, QSysInfo::Endian order) noexcept
\since 6.6 \since 6.6

View File

@ -101,9 +101,7 @@ public:
bool isNull() const noexcept; bool isNull() const noexcept;
#ifdef QT_SUPPORTS_INT128 #ifdef QT_SUPPORTS_INT128
constexpr explicit QUuid(quint128 uuid, QSysInfo::Endian order = QSysInfo::BigEndian) noexcept; static constexpr QUuid fromUInt128(quint128 uuid, QSysInfo::Endian order = QSysInfo::BigEndian) noexcept;
static constexpr QUuid fromUInt128(quint128 uuid, QSysInfo::Endian order = QSysInfo::BigEndian) noexcept
{ return QUuid{uuid, order}; }
constexpr quint128 toUInt128(QSysInfo::Endian order = QSysInfo::BigEndian) const noexcept; constexpr quint128 toUInt128(QSysInfo::Endian order = QSysInfo::BigEndian) const noexcept;
#endif #endif
@ -245,22 +243,23 @@ inline QUuid QUuid::fromBytes(const void *bytes, QSysInfo::Endian order) noexcep
} }
#ifdef QT_SUPPORTS_INT128 #ifdef QT_SUPPORTS_INT128
constexpr QUuid::QUuid(quint128 uuid, QSysInfo::Endian order) noexcept constexpr QUuid QUuid::fromUInt128(quint128 uuid, QSysInfo::Endian order) noexcept
: QUuid()
{ {
QUuid result = {};
if (order == QSysInfo::BigEndian) { if (order == QSysInfo::BigEndian) {
data1 = qFromBigEndian<quint32>(int(uuid)); result.data1 = qFromBigEndian<quint32>(int(uuid));
data2 = qFromBigEndian<quint16>(ushort(uuid >> 32)); result.data2 = qFromBigEndian<quint16>(ushort(uuid >> 32));
data3 = qFromBigEndian<quint16>(ushort(uuid >> 48)); result.data3 = qFromBigEndian<quint16>(ushort(uuid >> 48));
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
data4[i] = uchar(uuid >> (64 + i * 8)); result.data4[i] = uchar(uuid >> (64 + i * 8));
} else { } else {
data1 = qFromLittleEndian<quint32>(uint(uuid >> 96)); result.data1 = qFromLittleEndian<quint32>(uint(uuid >> 96));
data2 = qFromLittleEndian<quint16>(ushort(uuid >> 80)); result.data2 = qFromLittleEndian<quint16>(ushort(uuid >> 80));
data3 = qFromLittleEndian<quint16>(ushort(uuid >> 64)); result.data3 = qFromLittleEndian<quint16>(ushort(uuid >> 64));
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
data4[i] = uchar(uuid >> (56 - i * 8)); result.data4[i] = uchar(uuid >> (56 - i * 8));
} }
return result;
} }
constexpr quint128 QUuid::toUInt128(QSysInfo::Endian order) const noexcept constexpr quint128 QUuid::toUInt128(QSysInfo::Endian order) const noexcept

View File

@ -252,7 +252,7 @@ void tst_QUuid::uint128()
constexpr quint128 u = quint128(Q_UINT64_C(0xfc69b59ecc344436)) << 64 constexpr quint128 u = quint128(Q_UINT64_C(0xfc69b59ecc344436)) << 64
| Q_UINT64_C(0xa43cee95d128b8c5); // This is LE | Q_UINT64_C(0xa43cee95d128b8c5); // This is LE
constexpr quint128 be = qToBigEndian(u); constexpr quint128 be = qToBigEndian(u);
constexpr QUuid uuid(be); constexpr QUuid uuid = QUuid::fromUInt128(be);
static_assert(uuid.toUInt128() == be, "Round-trip through QUuid failed"); static_assert(uuid.toUInt128() == be, "Round-trip through QUuid failed");
QCOMPARE(uuid, uuidA); QCOMPARE(uuid, uuidA);
@ -262,7 +262,7 @@ void tst_QUuid::uint128()
quint128 le = qFromBigEndian(be); quint128 le = qFromBigEndian(be);
QCOMPARE(quint64(uuid.toUInt128(QSysInfo::LittleEndian) >> 64), quint64(le >> 64)); QCOMPARE(quint64(uuid.toUInt128(QSysInfo::LittleEndian) >> 64), quint64(le >> 64));
QCOMPARE(quint64(uuid.toUInt128(QSysInfo::LittleEndian)), quint64(le)); QCOMPARE(quint64(uuid.toUInt128(QSysInfo::LittleEndian)), quint64(le));
QCOMPARE(QUuid(le, QSysInfo::LittleEndian), uuidA); QCOMPARE(QUuid::fromUInt128(le, QSysInfo::LittleEndian), uuidA);
QUuid::Id128Bytes bytes = { .data128 = { qToBigEndian(u) } }; QUuid::Id128Bytes bytes = { .data128 = { qToBigEndian(u) } };
QUuid uuid2(bytes); QUuid uuid2(bytes);