mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
ff6c1a34ad
commit
2e5913d2ba
1 changed files with 4 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue