aboutsummaryrefslogtreecommitdiffstats
path: root/core/device.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-13 20:39:49 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-13 16:26:42 -0700
commit2e5913d2ba6c5b5c384121692045be52836ac6fa (patch)
tree07ec2dfc520f30584b47507684b78bb28c4d5c19 /core/device.cpp
parentff6c1a34ad362347e2a3903f3882837d8e455b73 (diff)
downloadsubsurface-2e5913d2ba6c5b5c384121692045be52836ac6fa.tar.gz
core: fix detection of duplicate device names
Recently (c9b8584bd2) the sort criteria of the device-table was changed from (model/id) to (id/model). However, that messed with the detection of duplicate device names: there, the code searched for the first element greater or equal to (model / 0). With the reversal of the sort criteria, this would now always give the first element. Therefore, do a simple non-binary search, which is much more robust. The binary search was a silly and pointless premature optimization anyway - don't do such things if not necessary! Since only one place in the code search for existence for a model-name, fold the corresponding function into that place. Moreover, change the code to do a case-insensitive compare. This is consistent with the dc_match_serial() code in core/libdivecomputer.c, where matching models is case-insensitive! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/device.cpp')
-rw-r--r--core/device.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/core/device.cpp b/core/device.cpp
index 5b59ce74d..c47cc821f 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -219,12 +219,6 @@ static const device *getDCExact(const QVector<device> &dcs, const divecomputer *
return it != dcs.end() && it->model == dc->model && it->deviceId == dc->deviceid ? &*it : NULL;
}
-static const device *getDC(const QVector<device> &dcs, const divecomputer *dc)
-{
- auto it = std::lower_bound(dcs.begin(), dcs.end(), device{dc->model, 0, {}, {}, {}});
- return it != dcs.end() && it->model == dc->model ? &*it : NULL;
-}
-
/*
* When setting the device ID, we also fill in the
* serial number and firmware version data
@@ -333,8 +327,10 @@ extern "C" void set_dc_nickname(struct dive *dive)
if (!empty_string(dc->model) && dc->deviceid &&
!getDCExact(device_table.devices, dc)) {
// we don't have this one, yet
- const device *existNode = getDC(device_table.devices, dc);
- if (existNode) {
+ auto it = std::find_if(device_table.devices.begin(), device_table.devices.end(),
+ [dc] (const device &dev)
+ { return !strcasecmp(qPrintable(dev.model), dc->model); });
+ if (it != device_table.devices.end()) {
// we already have this model but a different deviceid
QString simpleNick(dc->model);
if (dc->deviceid == 0)