diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-05-20 06:37:19 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-20 06:37:19 +0900 |
commit | 09e7c61feeeabac3dd983c11aca49b23155fff80 (patch) | |
tree | f82b271b89dd0f2f85cc78a1c0724df29204f439 /qt-ui | |
parent | b303f217a9d66ef031c58534b3796ddefbe362c5 (diff) | |
download | subsurface-09e7c61feeeabac3dd983c11aca49b23155fff80.tar.gz |
Consistently use for_each_dive (and use it correctly)
The way the macro is written there is no need to test the dive against
NULL before dereferencing.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/divelistview.cpp | 3 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 20 | ||||
-rw-r--r-- | qt-ui/subsurfacewebservices.cpp | 7 |
3 files changed, 11 insertions, 19 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index e6d82d5bc..c1d6e8d4d 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -706,8 +706,7 @@ void DiveListView::deleteDive() // so instead of using the for_each_dive macro I'm using an explicit for loop // to make this easier to understand int lastDiveNr = -1; - for (i = 0; i < dive_table.nr; i++) { - d = get_dive(i); + for_each_dive (i, d) { if (!d->selected) continue; delete_single_dive(i); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 5ed1b6704..96e2efc1c 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -270,10 +270,8 @@ void MainTab::enableEdition(EditMode newEditMode) // We may be editing one or more dives here. backup everything. struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; + int i; + for_each_dive(i, mydive) { if (!mydive->selected) continue; @@ -596,14 +594,12 @@ void MainTab::reload() #define EDIT_SELECTED_DIVES(WHAT) \ do { \ struct dive *mydive = NULL; \ + int _i; \ if (editMode == NONE) \ return; \ \ - for (int _i = 0; _i < dive_table.nr; _i++) { \ - mydive = get_dive(_i); \ - if (!mydive || mydive == current_dive)\ - continue; \ - if (!mydive->selected) \ + for_each_dive (_i, mydive) { \ + if (!mydive->selected || mydive == current_dive) \ continue; \ \ WHAT; \ @@ -836,10 +832,8 @@ void MainTab::rejectChanges() } struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; + int i; + for_each_dive (i, mydive) { if (!mydive->selected) continue; diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 5170b3a40..406939e6b 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -133,7 +133,9 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, } /* walk the dive list in chronological order */ - for (int i = 0; i < dive_table.nr; i++) { + int i; + struct dive *dive; + for_each_dive(i, dive) { FILE *f; char filename[PATH_MAX]; int streamsize; @@ -145,9 +147,6 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, * Get the i'th dive in XML format so we can process it. * We need to save to a file before we can reload it back into memory... */ - struct dive *dive = get_dive(i); - if (!dive) - continue; if (selected && !dive->selected) continue; f = tmpfile(); |