From 92deb7aa70e79db43b143c965c6386a6b06b4a2b Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 18 Sep 2018 10:55:29 +0200 Subject: 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 --- core/dive.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/dive.c b/core/dive.c index 688ccb989..67cfc5fa5 100644 --- a/core/dive.c +++ b/core/dive.c @@ -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); } -- cgit v1.2.3-70-g09d2