Cleanup: make surface sample in merge_one_sample() non-static

The merge_one_sample() function adds a sample to the destination
dive if dives are merged. For long periods between samples at surface
depths, it adds a surface interval.

To decrease the number of global objects, make the sample structure
non-static. Of course, initialization of an on-stack structure is
slower. Therefore move it into the corresponding if. Thus, the
structure will be initialized only once per surface-interval.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-09-18 10:55:29 +02:00 committed by Dirk Hohndel
parent 95e2c29827
commit 92deb7aa70

View file

@ -1828,19 +1828,21 @@ static void merge_one_sample(struct sample *sample, int time, struct divecompute
{
int last = dc->samples - 1;
if (last >= 0) {
static struct sample surface = { .bearing.degrees = -1, .ndl.seconds = -1 };
struct sample *prev = dc->sample + last;
int last_time = prev->time.seconds;
int last_depth = prev->depth.mm;
/* Init a few values from prev sample to avoid useless info in XML */
surface.bearing.degrees = prev->bearing.degrees;
surface.ndl.seconds = prev->ndl.seconds;
/*
* Only do surface events if the samples are more than
* a minute apart, and shallower than 5m
*/
if (time > last_time + 60 && last_depth < 5000) {
struct sample surface = { 0 };
/* Init a few values from prev sample to avoid useless info in XML */
surface.bearing.degrees = prev->bearing.degrees;
surface.ndl.seconds = prev->ndl.seconds;
add_sample(&surface, last_time + 20, dc);
add_sample(&surface, time - 20, dc);
}