diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-26 19:34:08 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-04-26 13:54:59 -0700 |
commit | 4f438d1e32a8a690c77f7eba8f80711e35e85df5 (patch) | |
tree | 6659080d80922bc1bb8a42de53341136d2b45c13 /desktop-widgets | |
parent | f43b3f56b252c2403b072298d4dbd613f03c479f (diff) | |
download | subsurface-4f438d1e32a8a690c77f7eba8f80711e35e85df5.tar.gz |
dive list: don't access selected dives via indices
When determining the selected dive sites to highlight them on the
map, the DiveListView code used the local indices of the selected
dives. However, that was unreasonably slow. Even though a layering
violation, let's access the core data structures directly. In my
tests this improved from 700 ms to 0 ms!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 746af88f2..e9c898641 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -515,12 +515,16 @@ void DiveListView::selectionChangeDone() // the dive-site selection is controlled by the filter not // by the selected dives. if (!DiveFilter::instance()->diveSiteMode()) { + // This is truly sad, but taking the list of selected indices and turning them + // into dive sites turned out to be unreasonably slow. Therefore, let's access + // the core list directly. In my tests, this went down from 700 to 0 ms! QVector<dive_site *> selectedSites; - for (QModelIndex index: selectionModel()->selectedRows()) { - const QAbstractItemModel *model = index.model(); - struct dive *dive = model->data(index, DiveTripModelBase::DIVE_ROLE).value<struct dive *>(); - if (dive && dive->dive_site && !selectedSites.contains(dive->dive_site)) - selectedSites.push_back(dive->dive_site); + selectedSites.reserve(amount_selected); + int i; + dive *d; + for_each_dive(i, d) { + if (d->selected && !d->hidden_by_filter && d->dive_site && !selectedSites.contains(d->dive_site)) + selectedSites.push_back(d->dive_site); } MapWidget::instance()->setSelected(selectedSites); } |