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/qlowenergyservice.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/qlowenergyservice.cpp')
-rw-r--r-- | src/bluetooth/qlowenergyservice.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 67bd7c77..9fb8e47c 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -454,9 +454,13 @@ QLowEnergyService::ServiceTypes QLowEnergyService::type() const */ QLowEnergyCharacteristic QLowEnergyService::characteristic(const QBluetoothUuid &uuid) const { - foreach (const QLowEnergyHandle handle, d_ptr->characteristicList.keys()) { - if (d_ptr->characteristicList[handle].uuid == uuid) - return QLowEnergyCharacteristic(d_ptr, handle); + CharacteristicDataMap::const_iterator charIt = d_ptr->characteristicList.constBegin(); + for ( ; charIt != d_ptr->characteristicList.constEnd(); ++charIt) { + const QLowEnergyHandle charHandle = charIt.key(); + const QLowEnergyServicePrivate::CharData &charDetails = charIt.value(); + + if (charDetails.uuid == uuid) + return QLowEnergyCharacteristic(d_ptr, charHandle); } return QLowEnergyCharacteristic(); |