summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-05-21 10:53:43 +0200
committerMarc Mutz <marc.mutz@qt.io>2024-05-28 12:39:27 +0000
commite0d87f70d87a63aa55a11ecb91f8d355767d61bd (patch)
treed14b615f57b6c920cd7205fb1c45fc4f2c5d223f /src
parent19e3ec4e2fe1c6d27570ee68480846e9dbf87db7 (diff)
Replace QUuid::toRfc4122() with toBytes() where possible
They're content-equivalent, except that the latter doesn't have to allocate a return value on the heap. Pick-to: 6.7 Change-Id: Ifcae47b487c80c2bac02900f08393b386cfe806c Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qcore_foundation.mm11
-rw-r--r--src/corelib/plugin/quuid.cpp2
2 files changed, 8 insertions, 5 deletions
diff --git a/src/corelib/kernel/qcore_foundation.mm b/src/corelib/kernel/qcore_foundation.mm
index a31040944f1..6d2451e078e 100644
--- a/src/corelib/kernel/qcore_foundation.mm
+++ b/src/corelib/kernel/qcore_foundation.mm
@@ -300,8 +300,8 @@ QUuid QUuid::fromCFUUID(CFUUIDRef uuid)
*/
CFUUIDRef QUuid::toCFUUID() const
{
- const QByteArray bytes = toRfc4122();
- return CFUUIDCreateFromUUIDBytes(0, *reinterpret_cast<const CFUUIDBytes *>(bytes.constData()));
+ const auto bytes = toBytes();
+ return CFUUIDCreateFromUUIDBytes(0, *reinterpret_cast<const CFUUIDBytes *>(&bytes));
}
/*!
@@ -333,8 +333,11 @@ QUuid QUuid::fromNSUUID(const NSUUID *uuid)
*/
NSUUID *QUuid::toNSUUID() const
{
- const QByteArray bytes = toRfc4122();
- return [[[NSUUID alloc] initWithUUIDBytes:*reinterpret_cast<const uuid_t *>(bytes.constData())] autorelease];
+ const auto bytes = toBytes();
+ static_assert(sizeof bytes == sizeof(uuid_t));
+ uuid_t u;
+ memcpy(&u, &bytes, sizeof(uuid_t));
+ return [[[NSUUID alloc] initWithUUIDBytes:u] autorelease];
}
// ----------------------------------------------------------------------------
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 42f21eea88c..8c3b758aaca 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -119,7 +119,7 @@ static QUuid _q_uuidFromHex(const char *src)
static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version)
{
QCryptographicHash hash(algorithm);
- hash.addData(ns.toRfc4122());
+ hash.addData(QByteArrayView{ns.toBytes()});
hash.addData(baseData);
QByteArrayView hashResult = hash.resultView();
Q_ASSERT(hashResult.size() >= 16);