From: Linus Torvalds <[email protected]> Date: Sun, 21 Feb 2016 15:20:39 -0800 Subject: [PATCH 3/4] pressure interpolation: further code simplification
With the two bigger simplications, this just re-organizes the code to do the "interpolate.pressure_time" update that is shared among all the "after segment start" cases in just one place. That leaves the get_pr_interpolate_data() much simpler, and makes it much clearer what it actually does. In particular, it becomes very obvious that "interpolate.pressure_time" is constant for one particular segment (it's the total pressure time), and that "interpolate.acc_pressure_time" is the one that gets updated for every entry. The next step is to only call this for the first entry, and then update just the "acc_pressure_time" in the caller. Signed-off-by: Linus Torvalds <[email protected]> --- I guess I could have combined this trivial simplification with the previous one, but it's somewhat different in type, and would have made it harder to see from the patch itself that it's all "obviously correct". Famous last words. Even trivial patches can end up having mistaeks. subsurface-core/gaspressures.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/subsurface-core/gaspressures.c b/subsurface-core/gaspressures.c index c63e16204ea1..5e7cd72ea785 100644 --- a/subsurface-core/gaspressures.c +++ b/subsurface-core/gaspressures.c @@ -187,16 +187,11 @@ static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t *segment, if (entry->sec < segment->t_start) continue; - if (entry->sec >= segment->t_end) { - interpolate.pressure_time += entry->pressure_time; + interpolate.pressure_time += entry->pressure_time; + if (entry->sec >= segment->t_end) break; - } - if (i <= cur) { + if (i <= cur) interpolate.acc_pressure_time += entry->pressure_time; - interpolate.pressure_time += entry->pressure_time; - continue; - } - interpolate.pressure_time += entry->pressure_time; } return interpolate; } -- 2.7.0.170.ge572fef _______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
