From ce7e74f62f378eae9cc473db76b10a748f5607b4 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 14 Sep 2020 17:09:42 +0200 Subject: cleanup: pass divecomputer to getDC() and getDCExact() helpers These are used to search for device nodes and were passed model and device id (for the exact version). However, all callers used them to search for the node corresponding to a specific struct divecomputer, so let's just pass that instead to make the caller site less complex. Signed-off-by: Berthold Stoeger --- core/device.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'core') diff --git a/core/device.cpp b/core/device.cpp index adbaff644..b6af22074 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -240,16 +240,16 @@ bool DiveComputerNode::operator<(const DiveComputerNode &a) const return std::tie(model, deviceId) < std::tie(a.model, a.deviceId); } -static const DiveComputerNode *getDCExact(const QVector &dcs, const QString &m, uint32_t d) +static const DiveComputerNode *getDCExact(const QVector &dcs, const divecomputer *dc) { - auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode{m, d, {}, {}, {}}); - return it != dcs.end() && it->model == m && it->deviceId == d ? &*it : NULL; + auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode{dc->model, dc->deviceid, {}, {}, {}}); + return it != dcs.end() && it->model == dc->model && it->deviceId == dc->deviceid ? &*it : NULL; } -static const DiveComputerNode *getDC(const QVector &dcs, const QString &m) +static const DiveComputerNode *getDC(const QVector &dcs, const divecomputer *dc) { - auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode{m, 0, {}, {}, {}}); - return it != dcs.end() && it->model == m ? &*it : NULL; + auto it = std::lower_bound(dcs.begin(), dcs.end(), DiveComputerNode{dc->model, 0, {}, {}, {}}); + return it != dcs.end() && it->model == dc->model ? &*it : NULL; } void DiveComputerNode::showchanges(const QString &n, const QString &s, const QString &f) const @@ -345,9 +345,9 @@ extern "C" void set_dc_nickname(struct dive *dive) for_each_dc (dive, dc) { if (!empty_string(dc->model) && dc->deviceid && - !getDCExact(dcList.dcs, dc->model, dc->deviceid)) { + !getDCExact(dcList.dcs, dc)) { // we don't have this one, yet - const DiveComputerNode *existNode = getDC(dcList.dcs, dc->model); + const DiveComputerNode *existNode = getDC(dcList.dcs, dc); if (existNode) { // we already have this model but a different deviceid QString simpleNick(dc->model); @@ -365,7 +365,7 @@ extern "C" void set_dc_nickname(struct dive *dive) QString get_dc_nickname(const struct divecomputer *dc) { - const DiveComputerNode *existNode = getDCExact(dcList.dcs, dc->model, dc->deviceid); + const DiveComputerNode *existNode = getDCExact(dcList.dcs, dc); if (existNode && !existNode->nickName.isEmpty()) return existNode->nickName; -- cgit v1.2.3-70-g09d2