mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: use binary search to find depth at event
Instead of looping over the whole data via the Qt model, do a simple binary search. Yes, this is premature optimization, but I had to. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8d4d35ea69
commit
9ddaf791ae
1 changed files with 6 additions and 3 deletions
|
@ -181,12 +181,15 @@ void DiveEventItem::eventVisibilityChanged(const QString&, bool)
|
||||||
|
|
||||||
static int depthAtTime(const DivePlotDataModel &model, int time)
|
static int depthAtTime(const DivePlotDataModel &model, int time)
|
||||||
{
|
{
|
||||||
QModelIndexList result = model.match(model.index(0, DivePlotDataModel::TIME), Qt::DisplayRole, time);
|
// Do a binary search for the timestamp
|
||||||
if (result.isEmpty()) {
|
const plot_info &pi = model.data();
|
||||||
|
auto it = std::lower_bound(pi.entry, pi.entry + pi.nr, time,
|
||||||
|
[](const plot_data &d1, int time) { return d1.sec < time; });
|
||||||
|
if (it == pi.entry + pi.nr || it->sec != time) {
|
||||||
qWarning("can't find a spot in the dataModel");
|
qWarning("can't find a spot in the dataModel");
|
||||||
return DEPTH_NOT_FOUND;
|
return DEPTH_NOT_FOUND;
|
||||||
}
|
}
|
||||||
return model.data(model.index(result.first().row(), DivePlotDataModel::DEPTH)).toInt();
|
return it->depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiveEventItem::isInteresting(const struct dive *d, const struct divecomputer *dc,
|
bool DiveEventItem::isInteresting(const struct dive *d, const struct divecomputer *dc,
|
||||||
|
|
Loading…
Add table
Reference in a new issue