QUuid: de-pessimize QDataStream operator
Use a stack buffer instead of a QByteArray to hold the 16 bytes for
the QUuid serialisation, replacing toRfc4122() with toBytes() and a
memcpy().
As drive-bys, drop the needless cast from char* to uchar*
(qToLittleEndian() has void* arguments, so char* is fine) and drop {}
around single-line if body.
Pick-to: 6.6
Change-Id: I6ffabcf07fc9a730a782e20e113999a0dcf15067
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
bb10
parent
3321101d8f
commit
72d51f1c42
|
|
@ -745,13 +745,15 @@ QByteArray QUuid::toRfc4122() const
|
|||
*/
|
||||
QDataStream &operator<<(QDataStream &s, const QUuid &id)
|
||||
{
|
||||
QByteArray bytes;
|
||||
constexpr int NumBytes = sizeof(QUuid);
|
||||
static_assert(NumBytes == 16, "Change the serialization format when this ever hits");
|
||||
char bytes[NumBytes];
|
||||
if (s.byteOrder() == QDataStream::BigEndian) {
|
||||
bytes = id.toRfc4122();
|
||||
const auto id128 = id.toBytes();
|
||||
static_assert(sizeof(id128) == NumBytes);
|
||||
memcpy(bytes, &id128, NumBytes);
|
||||
} else {
|
||||
// we know how many bytes a UUID has, I hope :)
|
||||
bytes = QByteArray(16, Qt::Uninitialized);
|
||||
uchar *data = reinterpret_cast<uchar *>(bytes.data());
|
||||
auto *data = bytes;
|
||||
|
||||
// for historical reasons, our little-endian serialization format
|
||||
// stores each of the UUID fields in little endian, instead of storing
|
||||
|
|
@ -769,9 +771,9 @@ QDataStream &operator<<(QDataStream &s, const QUuid &id)
|
|||
}
|
||||
}
|
||||
|
||||
if (s.writeRawData(bytes.data(), 16) != 16) {
|
||||
if (s.writeRawData(bytes, NumBytes) != NumBytes)
|
||||
s.setStatus(QDataStream::WriteFailed);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue