summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/compat/removed_api.cpp7
-rw-r--r--src/corelib/kernel/qcore_foundation.mm4
-rw-r--r--src/corelib/plugin/quuid.cpp29
-rw-r--r--src/corelib/plugin/quuid.h3
4 files changed, 26 insertions, 17 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp
index 9bd7944c41..d5d71ce75a 100644
--- a/src/corelib/compat/removed_api.cpp
+++ b/src/corelib/compat/removed_api.cpp
@@ -57,6 +57,13 @@ QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method)
return hash(QByteArrayView{data}, method);
}
+#include "quuid.h"
+
+QUuid QUuid::fromRfc4122(const QByteArray &bytes)
+{
+ return fromRfc4122(qToByteArrayViewIgnoringNull(bytes));
+}
+
// #include <qotherheader.h>
// // implement removed functions from qotherheader.h
diff --git a/src/corelib/kernel/qcore_foundation.mm b/src/corelib/kernel/qcore_foundation.mm
index 5520b1fb24..958f0e2bc7 100644
--- a/src/corelib/kernel/qcore_foundation.mm
+++ b/src/corelib/kernel/qcore_foundation.mm
@@ -321,7 +321,7 @@ QUuid QUuid::fromCFUUID(CFUUIDRef uuid)
if (!uuid)
return QUuid();
const CFUUIDBytes bytes = CFUUIDGetUUIDBytes(uuid);
- return QUuid::fromRfc4122(QByteArray::fromRawData(reinterpret_cast<const char *>(&bytes), sizeof(bytes)));
+ return QUuid::fromRfc4122(QByteArrayView(reinterpret_cast<const char *>(&bytes), sizeof(bytes)));
}
/*!
@@ -354,7 +354,7 @@ QUuid QUuid::fromNSUUID(const NSUUID *uuid)
return QUuid();
uuid_t bytes;
[uuid getUUIDBytes:bytes];
- return QUuid::fromRfc4122(QByteArray::fromRawData(reinterpret_cast<const char *>(bytes), sizeof(bytes)));
+ return QUuid::fromRfc4122(QByteArrayView(reinterpret_cast<const char *>(bytes), sizeof(bytes)));
}
/*!
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index be67898f8a..ea78fff5b3 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -151,16 +151,12 @@ static QUuid _q_uuidFromHex(const char *src)
static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version)
{
- QByteArray hashResult;
-
- // create a scope so later resize won't reallocate
- {
- QCryptographicHash hash(algorithm);
- hash.addData(ns.toRfc4122());
- hash.addData(baseData);
- hashResult = hash.result();
- }
- hashResult.resize(16); // Sha1 will be too long
+ QCryptographicHash hash(algorithm);
+ hash.addData(ns.toRfc4122());
+ hash.addData(baseData);
+ QByteArrayView hashResult = hash.resultView();
+ Q_ASSERT(hashResult.size() >= 16);
+ hashResult.truncate(16); // Sha1 will be too long
QUuid result = QUuid::fromRfc4122(hashResult);
@@ -524,20 +520,23 @@ QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData)
If the conversion fails, a null UUID is created.
+ \note In Qt versions prior to 6.3, this function took QByteArray, not
+ QByteArrayView.
+
\since 4.8
\sa toRfc4122(), QUuid()
*/
-QUuid QUuid::fromRfc4122(const QByteArray &bytes)
+QUuid QUuid::fromRfc4122(QByteArrayView bytes) noexcept
{
- if (bytes.isEmpty() || bytes.length() != 16)
+ if (bytes.isEmpty() || bytes.size() != 16)
return QUuid();
uint d1;
ushort d2, d3;
uchar d4[8];
- const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
+ const uchar *data = reinterpret_cast<const uchar *>(bytes.data());
d1 = qFromBigEndian<quint32>(data);
data += sizeof(quint32);
@@ -744,7 +743,7 @@ QDataStream &operator<<(QDataStream &s, const QUuid &id)
*/
QDataStream &operator>>(QDataStream &s, QUuid &id)
{
- QByteArray bytes(16, Qt::Uninitialized);
+ std::array<char, 16> bytes;
if (s.readRawData(bytes.data(), 16) != 16) {
s.setStatus(QDataStream::ReadPastEnd);
return s;
@@ -753,7 +752,7 @@ QDataStream &operator>>(QDataStream &s, QUuid &id)
if (s.byteOrder() == QDataStream::BigEndian) {
id = QUuid::fromRfc4122(bytes);
} else {
- const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
+ const uchar *data = reinterpret_cast<const uchar *>(bytes.data());
id.data1 = qFromLittleEndian<quint32>(data);
data += sizeof(quint32);
diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h
index 98ecced530..9192542684 100644
--- a/src/corelib/plugin/quuid.h
+++ b/src/corelib/plugin/quuid.h
@@ -105,7 +105,10 @@ public:
explicit QUuid(const QByteArray &);
QByteArray toByteArray(StringFormat mode = WithBraces) const;
QByteArray toRfc4122() const;
+#if QT_REMOVED_SINCE(6, 3)
static QUuid fromRfc4122(const QByteArray &);
+#endif
+ static QUuid fromRfc4122(QByteArrayView) noexcept;
bool isNull() const noexcept;
constexpr bool operator==(const QUuid &orig) const noexcept