Cleanup: pass gasmix by value

In a previous commit, the get_gasmix_* functions were changed to
return by value. For consistency, also pass gasmix by value.

Note that on common 64-bit platforms struct gasmix is the size
of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the
same space on the stack. On 32-bit platforms, the stack use
is probably doubled, but in return a dereference is avoided.

Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an
invasive change that going back to pointers is probably the
least of our worries.

This commit is a step in const-ifying input parameters (passing
by value is the ultimate way of signaling that the input parameter
will not be changed [unless there are references to said parameter]).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-08-16 19:10:10 +02:00 committed by Dirk Hohndel
parent 5c4569247a
commit 360f07e453
28 changed files with 214 additions and 215 deletions

View file

@ -94,8 +94,8 @@ void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2max_p)
for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i;
int o2 = get_o2(&cyl->gasmix);
int he = get_he(&cyl->gasmix);
int o2 = get_o2(cyl->gasmix);
int he = get_he(cyl->gasmix);
if (!is_cylinder_used(dive, i))
continue;
@ -135,7 +135,7 @@ int total_weight(struct dive *dive)
static int active_o2(struct dive *dive, struct divecomputer *dc, duration_t time)
{
struct gasmix gas = get_gasmix_at_time(dive, dc, time);
return get_o2(&gas);
return get_o2(gas);
}
/* calculate OTU for a dive - this only takes the first divecomputer into account */
@ -420,8 +420,8 @@ static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
for (j = t0; j < t1; j++) {
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
gasmix = get_gasmix(dive, dc, j, &ev, &gasmix);
add_segment(ds, depth_to_bar(depth, dive), &gasmix, 1, sample->setpoint.mbar,
gasmix = get_gasmix(dive, dc, j, &ev, gasmix);
add_segment(ds, depth_to_bar(depth, dive), gasmix, 1, sample->setpoint.mbar,
get_current_divemode(&dive->dc, j, &evd, &current_divemode), dive->sac);
}
}
@ -576,7 +576,7 @@ int init_decompression(struct deco_state *ds, struct dive *dive)
#endif
return surface_time;
}
add_segment(ds, surface_pressure, &air, surface_time, 0, dive->dc.divemode, prefs.decosac);
add_segment(ds, surface_pressure, air, surface_time, 0, dive->dc.divemode, prefs.decosac);
#if DECO_CALC_DEBUG & 2
printf("Tissues after surface intervall of %d:%02u:\n", FRACTION(surface_time, 60));
dump_tissues(ds);
@ -614,7 +614,7 @@ int init_decompression(struct deco_state *ds, struct dive *dive)
#endif
return surface_time;
}
add_segment(ds, surface_pressure, &air, surface_time, 0, dive->dc.divemode, prefs.decosac);
add_segment(ds, surface_pressure, air, surface_time, 0, dive->dc.divemode, prefs.decosac);
#if DECO_CALC_DEBUG & 2
printf("Tissues after surface intervall of %d:%02u:\n", FRACTION(surface_time, 60));
dump_tissues(ds);