mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:23:23 +00:00
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:
parent
95e2c29827
commit
92deb7aa70
1 changed files with 6 additions and 4 deletions
10
core/dive.c
10
core/dive.c
|
@ -1828,19 +1828,21 @@ static void merge_one_sample(struct sample *sample, int time, struct divecompute
|
||||||
{
|
{
|
||||||
int last = dc->samples - 1;
|
int last = dc->samples - 1;
|
||||||
if (last >= 0) {
|
if (last >= 0) {
|
||||||
static struct sample surface = { .bearing.degrees = -1, .ndl.seconds = -1 };
|
|
||||||
struct sample *prev = dc->sample + last;
|
struct sample *prev = dc->sample + last;
|
||||||
int last_time = prev->time.seconds;
|
int last_time = prev->time.seconds;
|
||||||
int last_depth = prev->depth.mm;
|
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
|
* Only do surface events if the samples are more than
|
||||||
* a minute apart, and shallower than 5m
|
* a minute apart, and shallower than 5m
|
||||||
*/
|
*/
|
||||||
if (time > last_time + 60 && last_depth < 5000) {
|
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, last_time + 20, dc);
|
||||||
add_sample(&surface, time - 20, dc);
|
add_sample(&surface, time - 20, dc);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue