summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/android
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-10 09:51:08 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-11 09:15:01 +0100
commit5488d1cd532b47c0a322a8f0ab31cf70f4e076da (patch)
treef5b64923ccc0c803ce4a53671f75f3d6c0808eec /src/bluetooth/android
parenta57a9a6598eb8fa2578ea8511b351b49d5b55ff0 (diff)
Avoid one large memory allocation per read descriptor/characteristic
We directly allocate into the QByteArray which continues to manage the memory for us. Change-Id: I39cd314a3cc9fcfd6bcf28836e0222d6d9a4f04f Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/android')
-rw-r--r--src/bluetooth/android/lowenergynotificationhub.cpp22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/bluetooth/android/lowenergynotificationhub.cpp b/src/bluetooth/android/lowenergynotificationhub.cpp
index 709bbc68..30b69edc 100644
--- a/src/bluetooth/android/lowenergynotificationhub.cpp
+++ b/src/bluetooth/android/lowenergynotificationhub.cpp
@@ -161,14 +161,9 @@ void LowEnergyNotificationHub::lowEnergy_characteristicRead(
QByteArray payload;
if (data) { //empty Java byte array is 0x0
jsize length = env->GetArrayLength(data);
- jbyte* nativeData = (jbyte*) malloc(length * sizeof(jbyte));
- if (!nativeData)
- return;
-
- env->GetByteArrayRegion(data, 0, length, nativeData);
- payload = QByteArray(reinterpret_cast<const char*>(nativeData),
- length); //takes deep copy of data
- free(nativeData);
+ payload.resize(length);
+ env->GetByteArrayRegion(data, 0, length,
+ reinterpret_cast<signed char*>(payload.data()));
}
QMetaObject::invokeMethod(hub, "characteristicRead", Qt::QueuedConnection,
@@ -202,14 +197,9 @@ void LowEnergyNotificationHub::lowEnergy_descriptorRead(
QByteArray payload;
if (data) { //empty Java byte array is 0x0
jsize length = env->GetArrayLength(data);
- jbyte* nativeData = (jbyte*) malloc(length * sizeof(jbyte));
- if (!nativeData)
- return;
-
- env->GetByteArrayRegion(data, 0, length, nativeData);
- payload = QByteArray(reinterpret_cast<const char*>(nativeData),
- length); //takes deep copy of data
- free(nativeData);
+ payload.resize(length);
+ env->GetByteArrayRegion(data, 0, length,
+ reinterpret_cast<signed char*>(payload.data()));
}
QMetaObject::invokeMethod(hub, "descriptorRead", Qt::QueuedConnection,