diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2015-09-14 02:35:20 +0400 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2015-09-16 13:35:56 +0000 |
commit | 7a0a5edcc747bdef71f11638a8c3c47fb31f8be6 (patch) | |
tree | 50f97c613097a084abffa7880fd252c5b0b74071 /src/bluetooth/qlowenergycharacteristic.cpp | |
parent | ff59294c0d7a7464870a7a7d3bc1449c7a7695a7 (diff) |
[Bluetooth] Optimize loops
Decrease complexity from O(N+N*logN) to just O(N) for cases like
foreach (Key key, map.keys())
Value value = map.value(key);
, by rewriting with use of iterators.
Change-Id: I81f1334797f16b624293fcebdee885b2be3c89f1
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qlowenergycharacteristic.cpp')
-rw-r--r-- | src/bluetooth/qlowenergycharacteristic.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp index aba4a66b..885b1337 100644 --- a/src/bluetooth/qlowenergycharacteristic.cpp +++ b/src/bluetooth/qlowenergycharacteristic.cpp @@ -338,11 +338,18 @@ QLowEnergyDescriptor QLowEnergyCharacteristic::descriptor(const QBluetoothUuid & if (d_ptr.isNull() || !data) return QLowEnergyDescriptor(); - QList<QLowEnergyHandle> descriptorKeys = d_ptr->characteristicList[data->handle]. - descriptorList.keys(); - foreach (const QLowEnergyHandle descHandle, descriptorKeys) { - if (uuid == d_ptr->characteristicList[data->handle].descriptorList[descHandle].uuid) - return QLowEnergyDescriptor(d_ptr, data->handle, descHandle); + CharacteristicDataMap::const_iterator charIt = d_ptr->characteristicList.constFind(data->handle); + if (charIt != d_ptr->characteristicList.constEnd()) { + const QLowEnergyServicePrivate::CharData &charDetails = charIt.value(); + + DescriptorDataMap::const_iterator descIt = charDetails.descriptorList.constBegin(); + for ( ; descIt != charDetails.descriptorList.constEnd(); ++descIt) { + const QLowEnergyHandle descHandle = descIt.key(); + const QLowEnergyServicePrivate::DescData &descDetails = descIt.value(); + + if (descDetails.uuid == uuid) + return QLowEnergyDescriptor(d_ptr, data->handle, descHandle); + } } return QLowEnergyDescriptor(); |