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>
This commit is contained in:
parent
19e3ec4e2f
commit
e0d87f70d8
@ -300,8 +300,8 @@ QUuid QUuid::fromCFUUID(CFUUIDRef uuid)
|
|||||||
*/
|
*/
|
||||||
CFUUIDRef QUuid::toCFUUID() const
|
CFUUIDRef QUuid::toCFUUID() const
|
||||||
{
|
{
|
||||||
const QByteArray bytes = toRfc4122();
|
const auto bytes = toBytes();
|
||||||
return CFUUIDCreateFromUUIDBytes(0, *reinterpret_cast<const CFUUIDBytes *>(bytes.constData()));
|
return CFUUIDCreateFromUUIDBytes(0, *reinterpret_cast<const CFUUIDBytes *>(&bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -333,8 +333,11 @@ QUuid QUuid::fromNSUUID(const NSUUID *uuid)
|
|||||||
*/
|
*/
|
||||||
NSUUID *QUuid::toNSUUID() const
|
NSUUID *QUuid::toNSUUID() const
|
||||||
{
|
{
|
||||||
const QByteArray bytes = toRfc4122();
|
const auto bytes = toBytes();
|
||||||
return [[[NSUUID alloc] initWithUUIDBytes:*reinterpret_cast<const uuid_t *>(bytes.constData())] autorelease];
|
static_assert(sizeof bytes == sizeof(uuid_t));
|
||||||
|
uuid_t u;
|
||||||
|
memcpy(&u, &bytes, sizeof(uuid_t));
|
||||||
|
return [[[NSUUID alloc] initWithUUIDBytes:u] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -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)
|
static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version)
|
||||||
{
|
{
|
||||||
QCryptographicHash hash(algorithm);
|
QCryptographicHash hash(algorithm);
|
||||||
hash.addData(ns.toRfc4122());
|
hash.addData(QByteArrayView{ns.toBytes()});
|
||||||
hash.addData(baseData);
|
hash.addData(baseData);
|
||||||
QByteArrayView hashResult = hash.resultView();
|
QByteArrayView hashResult = hash.resultView();
|
||||||
Q_ASSERT(hashResult.size() >= 16);
|
Q_ASSERT(hashResult.size() >= 16);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user