summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@nokia.com>2011-05-20 07:48:30 (GMT)
committerLiang Qi <liang.qi@nokia.com>2011-05-20 12:28:14 (GMT)
commitd56d7f107f9d18810d742ac4d3a2e36077722cb8 (patch)
treed08b893e252a4743214ca1f3e00ed1e7f47836ae /src
parent06873e467d98ad60d827afae29500bf2ff783c03 (diff)
downloadQt-d56d7f107f9d18810d742ac4d3a2e36077722cb8.zip
Qt-d56d7f107f9d18810d742ac4d3a2e36077722cb8.tar.gz
Qt-d56d7f107f9d18810d742ac4d3a2e36077722cb8.tar.bz2
QDataStream: speedup steaming of QUuid.
By reading and writing as a whole block, because the size of QUuid is fixed. Reviewed-by: joao
Diffstat (limited to 'src')
-rw-r--r--src/corelib/plugin/quuid.cpp64
1 files changed, 47 insertions, 17 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 4b1856d..ddc388c 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -591,11 +591,30 @@ QByteArray QUuid::toRfc4122() const
*/
QDataStream &operator<<(QDataStream &s, const QUuid &id)
{
- s << (quint32)id.data1;
- s << (quint16)id.data2;
- s << (quint16)id.data3;
- for (int i = 0; i < 8; i++)
- s << (quint8)id.data4[i];
+ QByteArray bytes;
+ if (s.byteOrder() == QDataStream::BigEndian) {
+ bytes = id.toRfc4122();
+ } else {
+ // we know how many bytes a UUID has, I hope :)
+ bytes = QByteArray(16, Qt::Uninitialized);
+ uchar *data = reinterpret_cast<uchar*>(bytes.data());
+
+ qToLittleEndian(id.data1, data);
+ data += sizeof(quint32);
+ qToLittleEndian(id.data2, data);
+ data += sizeof(quint16);
+ qToLittleEndian(id.data3, data);
+ data += sizeof(quint16);
+
+ for (int i = 0; i < 8; ++i) {
+ *(data) = id.data4[i];
+ data++;
+ }
+ }
+
+ if (s.writeRawData(bytes.data(), 16) != 16) {
+ s.setStatus(QDataStream::WriteFailed);
+ }
return s;
}
@@ -605,19 +624,30 @@ QDataStream &operator<<(QDataStream &s, const QUuid &id)
*/
QDataStream &operator>>(QDataStream &s, QUuid &id)
{
- quint32 u32;
- quint16 u16;
- quint8 u8;
- s >> u32;
- id.data1 = u32;
- s >> u16;
- id.data2 = u16;
- s >> u16;
- id.data3 = u16;
- for (int i = 0; i < 8; i++) {
- s >> u8;
- id.data4[i] = u8;
+ QByteArray bytes(16, Qt::Uninitialized);
+ if (s.readRawData(bytes.data(), 16) != 16) {
+ s.setStatus(QDataStream::ReadPastEnd);
+ return s;
}
+
+ if (s.byteOrder() == QDataStream::BigEndian) {
+ id = QUuid::fromRfc4122(bytes);
+ } else {
+ const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
+
+ id.data1 = qFromLittleEndian<quint32>(data);
+ data += sizeof(quint32);
+ id.data2 = qFromLittleEndian<quint16>(data);
+ data += sizeof(quint16);
+ id.data3 = qFromLittleEndian<quint16>(data);
+ data += sizeof(quint16);
+
+ for (int i = 0; i < 8; ++i) {
+ id.data4[i] = *(data);
+ data++;
+ }
+ }
+
return s;
}
#endif // QT_NO_DATASTREAM