summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-08-26 11:37:47 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-08-27 10:08:30 +0200
commit9f4c45b58b82b59740dc60e22cba6894efd6c164 (patch)
tree578325ff39d2042546830ac5323e2ecab7c7cb77
parent8a02c2ffd83afc17a4ea825e4954705ce21da99c (diff)
Improve quint128 to QBluetoothUuid conversion performance
The change improves the performance between 8-10%. Change-Id: I342e669d3f18cd2179b65f1af172db52303ff44c Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
-rw-r--r--src/bluetooth/qbluetoothuuid.cpp14
-rw-r--r--tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp13
2 files changed, 16 insertions, 11 deletions
diff --git a/src/bluetooth/qbluetoothuuid.cpp b/src/bluetooth/qbluetoothuuid.cpp
index 7229889d..15d238e1 100644
--- a/src/bluetooth/qbluetoothuuid.cpp
+++ b/src/bluetooth/qbluetoothuuid.cpp
@@ -468,17 +468,9 @@ QBluetoothUuid::QBluetoothUuid(quint32 uuid)
*/
QBluetoothUuid::QBluetoothUuid(quint128 uuid)
{
- // TODO: look at the memcpy(), should not be needed
- quint32 tmp32;
- memcpy(&tmp32, &uuid.data[0], 4);
- data1 = qFromBigEndian<quint32>(tmp32);
-
- quint16 tmp16;
- memcpy(&tmp16, &uuid.data[4], 2);
- data2 = qFromBigEndian<quint16>(tmp16);
-
- memcpy(&tmp16, &uuid.data[6], 2);
- data3 = qFromBigEndian<quint16>(tmp16);
+ data1 = qFromBigEndian<quint32>(*reinterpret_cast<quint32 *>(&uuid.data[0]));
+ data2 = qFromBigEndian<quint16>(*reinterpret_cast<quint16 *>(&uuid.data[4]));
+ data3 = qFromBigEndian<quint16>(*reinterpret_cast<quint16 *>(&uuid.data[6]));
memcpy(data4, &uuid.data[8], 8);
}
diff --git a/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp b/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp
index a040a5c5..e905eb94 100644
--- a/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp
+++ b/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp
@@ -64,6 +64,7 @@ private slots:
void tst_conversion();
void tst_comparison_data();
void tst_comparison();
+ void tst_quint128ToUuid();
};
tst_QBluetoothUuid::tst_QBluetoothUuid()
@@ -375,6 +376,18 @@ void tst_QBluetoothUuid::tst_comparison()
}
}
}
+
+void tst_QBluetoothUuid::tst_quint128ToUuid()
+{
+ QBluetoothUuid temp(QString("{67C8770B-44F1-410A-AB9A-F9B5446F13EE}"));
+ quint128 array = temp.toUInt128();
+ QBluetoothUuid u(array);
+ QVERIFY(temp == u);
+
+ QBENCHMARK {
+ QBluetoothUuid u(array);
+ }
+}
QTEST_MAIN(tst_QBluetoothUuid)
#include "tst_qbluetoothuuid.moc"