diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-07-06 13:22:26 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-11-09 19:19:04 +0100 |
commit | 7e1425796d45870fd845f7e92b478730ba7a4e6a (patch) | |
tree | dcc699ab3502bc7134820e5683dcb1babca02e85 | |
parent | 2fd4cb5fe1415a204610b89b22c0863c0703175e (diff) | |
download | subsurface-7e1425796d45870fd845f7e92b478730ba7a4e6a.tar.gz |
Profile: turn INSERT_ENTRY macro into helper function
The only apparent reason that this was a macro is that it automatically
increased the "index" and "entry" counts. But incrementing these explicitly
seems reasonable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/profile.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/core/profile.c b/core/profile.c index a012eb0cf..9fb2566bf 100644 --- a/core/profile.c +++ b/core/profile.c @@ -493,17 +493,19 @@ static void calculate_max_limits_new(struct dive *dive, struct divecomputer *giv /* copy the previous entry (we know this exists), update time and depth * and zero out the sensor pressure (since this is a synthetic entry) * increment the entry pointer and the count of synthetic entries. */ -#define INSERT_ENTRY(_time, _depth, _sac) \ - *entry = entry[-1]; \ - entry->sec = _time; \ - entry->depth = _depth; \ - entry->running_sum = (entry - 1)->running_sum + (_time - (entry - 1)->sec) * (_depth + (entry - 1)->depth) / 2; \ - memset(entry->pressure, 0, sizeof(entry->pressure)); \ - entry->sac = _sac; \ - entry->ndl = -1; \ - entry->bearing = -1; \ - entry++; \ - idx++ +static void insert_entry(struct plot_info *pi, int idx, int time, int depth, int sac) +{ + struct plot_data *entry = pi->entry + idx; + struct plot_data *prev = pi->entry + idx - 1; + *entry = *prev; + entry->sec = time; + entry->depth = depth; + entry->running_sum = prev->running_sum + (time - prev->sec) * (depth + prev->depth) / 2; + memset(entry->pressure, 0, sizeof(entry->pressure)); + entry->sac = sac; + entry->ndl = -1; + entry->bearing = -1; +} void free_plot_info_data(struct plot_info *pi) { @@ -562,12 +564,16 @@ static void populate_plot_entries(struct dive *dive, struct divecomputer *dc, st /* Add events if they are between plot entries */ while (ev && (int)ev->time.seconds < lasttime + offset) { - INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta), sac); + insert_entry(pi, idx, ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta), sac); + entry++; + idx++; ev = ev->next; } /* now insert the time interpolated entry */ - INSERT_ENTRY(lasttime + offset, interpolate(lastdepth, depth, offset, delta), sac); + insert_entry(pi, idx, lasttime + offset, interpolate(lastdepth, depth, offset, delta), sac); + entry++; + idx++; /* skip events that happened at this time */ while (ev && (int)ev->time.seconds == lasttime + offset) @@ -576,7 +582,9 @@ static void populate_plot_entries(struct dive *dive, struct divecomputer *dc, st /* Add events if they are between plot entries */ while (ev && (int)ev->time.seconds < time) { - INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta), sac); + insert_entry(pi, idx, ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta), sac); + entry++; + idx++; ev = ev->next; } @@ -628,8 +636,10 @@ static void populate_plot_entries(struct dive *dive, struct divecomputer *dc, st int time = ev->time.seconds; if (time > lasttime) { - INSERT_ENTRY(ev->time.seconds, 0, 0); + insert_entry(pi, idx, ev->time.seconds, 0, 0); lasttime = time; + idx++; + entry++; } ev = ev->next; } @@ -640,8 +650,6 @@ static void populate_plot_entries(struct dive *dive, struct divecomputer *dc, st pi->nr = idx; } -#undef INSERT_ENTRY - /* * Calculate the sac rate between the two plot entries 'first' and 'last'. * |