diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-08-16 19:10:10 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-08-23 05:16:38 -0700 |
commit | 360f07e4533d4ede7ba494724382fc8dbcb4649c (patch) | |
tree | 73a222ad3469e8a7fd085cb2671d12dac664aeac /core/profile.c | |
parent | 5c4569247a31cf9f52238bd2b3f9c87b8f79933a (diff) | |
download | subsurface-360f07e4533d4ede7ba494724382fc8dbcb4649c.tar.gz |
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>
Diffstat (limited to 'core/profile.c')
-rw-r--r-- | core/profile.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/core/profile.c b/core/profile.c index 56cc85aac..cfda49163 100644 --- a/core/profile.c +++ b/core/profile.c @@ -333,7 +333,7 @@ int get_cylinder_index(struct dive *dive, struct event *ev) fprintf(stderr, "Still looking up cylinder based on gas mix in get_cylinder_index()!\n"); mix = get_gasmix_from_event(dive, ev); - best = find_best_gasmix_match(&mix, dive->cylinder, 0); + best = find_best_gasmix_match(mix, dive->cylinder, 0); return best < 0 ? 0 : best; } @@ -760,14 +760,14 @@ static void fill_sac(struct dive *dive, struct plot_info *pi, int idx, unsigned /* * Create a bitmap of cylinders that match our current gasmix */ -static unsigned int matching_gases(struct dive *dive, struct gasmix *gasmix) +static unsigned int matching_gases(struct dive *dive, struct gasmix gasmix) { int i; unsigned int gases = 0; for (i = 0; i < MAX_CYLINDERS; i++) { cylinder_t *cyl = dive->cylinder + i; - if (same_gasmix(gasmix, &cyl->gasmix)) + if (same_gasmix(gasmix, cyl->gasmix)) gases |= 1 << i; } return gases; @@ -781,10 +781,10 @@ static void calculate_sac(struct dive *dive, struct divecomputer *dc, struct plo for (int i = 0; i < pi->nr; i++) { struct plot_data *entry = pi->entry + i; - struct gasmix newmix = get_gasmix(dive, dc, entry->sec, &ev, &gasmix); - if (!same_gasmix(&newmix, &gasmix)) { + struct gasmix newmix = get_gasmix(dive, dc, entry->sec, &ev, gasmix); + if (!same_gasmix(newmix, gasmix)) { gasmix = newmix; - gases = matching_gases(dive, &newmix); + gases = matching_gases(dive, newmix); } fill_sac(dive, pi, i, gases); @@ -907,7 +907,7 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc #ifndef SUBSURFACE_MOBILE /* calculate DECO STOP / TTS / NDL */ -static void calculate_ndl_tts(struct deco_state *ds, struct dive *dive, struct plot_data *entry, struct gasmix *gasmix, double surface_pressure,enum divemode_t divemode) +static void calculate_ndl_tts(struct deco_state *ds, struct dive *dive, struct plot_data *entry, struct gasmix gasmix, double surface_pressure,enum divemode_t divemode) { /* FIXME: This should be configurable */ /* ascent speed up to first deco stop */ @@ -1026,7 +1026,7 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne int time_stepsize = 20; current_divemode = get_current_divemode(dc, entry->sec, &evd, ¤t_divemode); - gasmix = get_gasmix(dive, dc, t1, &ev, &gasmix); + gasmix = get_gasmix(dive, dc, t1, &ev, gasmix); entry->ambpressure = depth_to_bar(entry->depth, dive); entry->gfline = get_gf(ds, entry->ambpressure, dive) * (100.0 - AMB_PERCENTAGE) + AMB_PERCENTAGE; if (t0 > t1) { @@ -1040,7 +1040,7 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne for (j = t0 + time_stepsize; j <= t1; j += time_stepsize) { int depth = interpolate(entry[-1].depth, entry[0].depth, j - t0, t1 - t0); add_segment(ds, depth_to_bar(depth, dive), - &gasmix, time_stepsize, entry->o2pressure.mbar, current_divemode, entry->sac); + gasmix, time_stepsize, entry->o2pressure.mbar, current_divemode, entry->sac); entry->icd_warning = ds->icd_warning; if ((t1 - j < time_stepsize) && (j < t1)) time_stepsize = t1 - j; @@ -1115,7 +1115,7 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne /* We are going to mess up deco state, so store it for later restore */ struct deco_state *cache_data = NULL; cache_deco_state(ds, &cache_data); - calculate_ndl_tts(ds, dive, entry, &gasmix, surface_pressure, current_divemode); + calculate_ndl_tts(ds, dive, entry, gasmix, surface_pressure, current_divemode); if (decoMode() == VPMB && !in_planner() && i == pi->nr - 1) final_tts = entry->tts_calc; /* Restore "real" deco state for next real time step */ @@ -1213,15 +1213,15 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer int fn2, fhe; struct plot_data *entry = pi->entry + i; - gasmix = get_gasmix(dive, dc, entry->sec, &evg, &gasmix); + gasmix = get_gasmix(dive, dc, entry->sec, &evg, gasmix); amb_pressure = depth_to_bar(entry->depth, dive); current_divemode = get_current_divemode(dc, entry->sec, &evd, ¤t_divemode); - fill_pressures(&entry->pressures, amb_pressure, &gasmix, (current_divemode == OC) ? 0.0 : entry->o2pressure.mbar / 1000.0, current_divemode); + fill_pressures(&entry->pressures, amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry->o2pressure.mbar / 1000.0, current_divemode); fn2 = (int)(1000.0 * entry->pressures.n2 / amb_pressure); fhe = (int)(1000.0 * entry->pressures.he / amb_pressure); if (dc->divemode == PSCR) { // OC pO2 is calulated for PSCR with or without external PO2 monitoring. - struct gasmix gasmix2 = get_gasmix(dive, dc, entry->sec, &evg, &gasmix); - entry->scr_OC_pO2.mbar = (int) depth_to_mbar(entry->depth, dive) * get_o2(&gasmix2) / 1000; + struct gasmix gasmix2 = get_gasmix(dive, dc, entry->sec, &evg, gasmix); + entry->scr_OC_pO2.mbar = (int) depth_to_mbar(entry->depth, dive) * get_o2(gasmix2) / 1000; } /* Calculate MOD, EAD, END and EADD based on partial pressures calculated before @@ -1229,7 +1229,7 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer * END takes O₂ + N₂ (air) into account ("Narcotic" for trimix dives) * EAD just uses N₂ ("Air" for nitrox dives) */ pressure_t modpO2 = { .mbar = (int)(prefs.modpO2 * 1000) }; - entry->mod = (double)gas_mod(&gasmix, modpO2, dive, 1).mm; + entry->mod = (double)gas_mod(gasmix, modpO2, dive, 1).mm; entry->end = (entry->depth + 10000) * (1000 - fhe) / 1000.0 - 10000; entry->ead = (entry->depth + 10000) * fn2 / (double)N2_IN_AIR - 10000; entry->eadd = (entry->depth + 10000) * @@ -1237,7 +1237,7 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer entry->pressures.n2 / amb_pressure * N2_DENSITY + entry->pressures.he / amb_pressure * HE_DENSITY) / (O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 - 10000; - entry->density = gas_density(&gasmix, depth_to_mbar(entry->depth, dive)); + entry->density = gas_density(gasmix, depth_to_mbar(entry->depth, dive)); if (entry->mod < 0) entry->mod = 0; if (entry->ead < 0) @@ -1387,11 +1387,10 @@ static void plot_string(struct plot_info *pi, struct plot_data *entry, struct me depthvalue = get_depth_units(entry->depth, NULL, &depth_unit); put_format_loc(b, translate("gettextFromC", "@: %d:%02d\nD: %.1f%s\n"), FRACTION(entry->sec, 60), depthvalue, depth_unit); for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { - struct gasmix *mix; int mbar = GET_PRESSURE(entry, cyl); if (!mbar) continue; - mix = &displayed_dive.cylinder[cyl].gasmix; + struct gasmix mix = displayed_dive.cylinder[cyl].gasmix; pressurevalue = get_pressure_units(mbar, &pressure_unit); put_format_loc(b, translate("gettextFromC", "P: %d%s (%s)\n"), pressurevalue, pressure_unit, gasname(mix)); } |