diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-17 23:05:03 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-17 15:20:52 -0700 |
commit | 2c6b1a99af103232d420a09023e9e0e6ccee9084 (patch) | |
tree | 70f38609c2a7a8e09c986c0bdfbd7d2695072501 /core/dive.c | |
parent | 4931b5a8e61ab40d393a13742bec4e26fd4da155 (diff) | |
download | subsurface-2c6b1a99af103232d420a09023e9e0e6ccee9084.tar.gz |
Cleanup: simplify dive_getUniqID()
dive_getUniqID() is used to create unique dive ids, which are
stable during application lifetime. It was passed a dive, checked
that the id was not set (if it was that it is know to the application)
and set a new id (in contradiction to its name!) if it hadn't any.
There were three callers:
alloc_dive(): called the function on a zeroed dive struct.
fixup_dive(): called the function only if the dive had a 0 id.
MainWindow::setupForAddAndPlan(): called the function on a zeroed dive
struct.
Thus, in all three callers the id is guaranteed to be zero and
the whole keeping-track-of-ids logic is moot. Remove the logic,
don't pass a dive struct to dive_getUniqID() and move the function
to the C-backend.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/dive.c')
-rw-r--r-- | core/dive.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/core/dive.c b/core/dive.c index 78263dfab..c977183a3 100644 --- a/core/dive.c +++ b/core/dive.c @@ -454,6 +454,15 @@ double get_weight_units(unsigned int grams, int *frac, const char **units) return value; } +// we need this to be uniq. oh, and it has no meaning whatsoever +// - that's why we have the silly initial number and increment by 3 :-) +int dive_getUniqID() +{ + static int maxId = 83529; + maxId += 3; + return maxId; +} + struct dive *alloc_dive(void) { struct dive *dive; @@ -462,7 +471,7 @@ struct dive *alloc_dive(void) if (!dive) exit(1); memset(dive, 0, sizeof(*dive)); - dive->id = dive_getUniqID(dive); + dive->id = dive_getUniqID(); return dive; } @@ -1784,7 +1793,7 @@ struct dive *fixup_dive(struct dive *dive) /* we should always have a uniq ID as that gets assigned during alloc_dive(), * but we want to make sure... */ if (!dive->id) - dive->id = dive_getUniqID(dive); + dive->id = dive_getUniqID(); return dive; } |