diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-08-10 16:03:46 +0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-08-14 20:13:54 +0000 |
commit | 9c1d20337a5585c620e13776f9c33582f2e479d8 (patch) | |
tree | 8160d1f067aee186e97fdcc16a5638ee3ae26018 | |
parent | 3693dd74febbd928eefa8291a05f6ef5a65ffe63 (diff) |
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>
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 13 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.h | 25 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/quuid/tst_quuid.cpp | 4 |
3 files changed, 14 insertions, 28 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index b446edbc95..2a2f4cb00d 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -311,19 +311,6 @@ static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCrypto */ /*! - \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 \since 6.6 diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 2f1927afa2..140f20a80e 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -101,9 +101,7 @@ public: bool isNull() const noexcept; #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 - { return QUuid{uuid, order}; } + static constexpr QUuid fromUInt128(quint128 uuid, QSysInfo::Endian order = QSysInfo::BigEndian) noexcept; constexpr quint128 toUInt128(QSysInfo::Endian order = QSysInfo::BigEndian) const noexcept; #endif @@ -245,22 +243,23 @@ inline QUuid QUuid::fromBytes(const void *bytes, QSysInfo::Endian order) noexcep } #ifdef QT_SUPPORTS_INT128 -constexpr QUuid::QUuid(quint128 uuid, QSysInfo::Endian order) noexcept - : QUuid() +constexpr QUuid QUuid::fromUInt128(quint128 uuid, QSysInfo::Endian order) noexcept { + QUuid result = {}; if (order == QSysInfo::BigEndian) { - data1 = qFromBigEndian<quint32>(int(uuid)); - data2 = qFromBigEndian<quint16>(ushort(uuid >> 32)); - data3 = qFromBigEndian<quint16>(ushort(uuid >> 48)); + result.data1 = qFromBigEndian<quint32>(int(uuid)); + result.data2 = qFromBigEndian<quint16>(ushort(uuid >> 32)); + result.data3 = qFromBigEndian<quint16>(ushort(uuid >> 48)); for (int i = 0; i < 8; ++i) - data4[i] = uchar(uuid >> (64 + i * 8)); + result.data4[i] = uchar(uuid >> (64 + i * 8)); } else { - data1 = qFromLittleEndian<quint32>(uint(uuid >> 96)); - data2 = qFromLittleEndian<quint16>(ushort(uuid >> 80)); - data3 = qFromLittleEndian<quint16>(ushort(uuid >> 64)); + result.data1 = qFromLittleEndian<quint32>(uint(uuid >> 96)); + result.data2 = qFromLittleEndian<quint16>(ushort(uuid >> 80)); + result.data3 = qFromLittleEndian<quint16>(ushort(uuid >> 64)); 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 diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp index 08f548a834..80924daa60 100644 --- a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp +++ b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp @@ -252,7 +252,7 @@ void tst_QUuid::uint128() constexpr quint128 u = quint128(Q_UINT64_C(0xfc69b59ecc344436)) << 64 | Q_UINT64_C(0xa43cee95d128b8c5); // This is LE 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"); QCOMPARE(uuid, uuidA); @@ -262,7 +262,7 @@ void tst_QUuid::uint128() quint128 le = qFromBigEndian(be); QCOMPARE(quint64(uuid.toUInt128(QSysInfo::LittleEndian) >> 64), quint64(le >> 64)); 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 uuid2(bytes); |