aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-09-18 10:55:29 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-19 14:43:54 -0700
commit92deb7aa70e79db43b143c965c6386a6b06b4a2b (patch)
tree396c1a05ad7385c49084d4103425fd7fa60a9a8a /core
parent95e2c29827f6d1fdf52af67b91e89c104463cf26 (diff)
downloadsubsurface-92deb7aa70e79db43b143c965c6386a6b06b4a2b.tar.gz
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>
Diffstat (limited to 'core')
-rw-r--r--core/dive.c10
1 files changed, 6 insertions, 4 deletions
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);
}