From: Linus Torvalds <[email protected]>
Date: Sun, 21 Feb 2016 15:09:46 -0800
Subject: [PATCH 1/4] pressure interpolation: get rid of pointless and confusing 
code

In the function fill_missing_tank_pressures(), we only ever call
get_pr_interpolate_data() if "pressure" is zero.  So passing it in as an
argument, and then testing whether it is zero or not, is just totally
pointless, and only obfuscates things.

This whole thing seems to be due to people editing the code over time,
with the tests becoming superfluous as the code around it changed, and
nobody looking at whether it actually made sense any more.

Signed-off-by: Linus Torvalds <[email protected]>
---

The _only_ call point of get_pr_interpolate_data() literally has code like

                if (pressure) {                 // If there is a valid pressure 
value,
                        cur_pr[cyl] = pressure; // set current pressure
                        continue;               // and skip to next point.
                }

a few lines before the call. So we very much know that "pressure" is zero, 
and there is no point in passing it in as an argument or testing it.

 subsurface-core/gaspressures.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/subsurface-core/gaspressures.c b/subsurface-core/gaspressures.c
index 66ec7e3aac84..43c0a11cfb0d 100644
--- a/subsurface-core/gaspressures.c
+++ b/subsurface-core/gaspressures.c
@@ -171,7 +171,7 @@ void dump_pr_interpolate(int i, pr_interpolate_t 
interpolate_pr)
 #endif
 
 
-static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t 
*segment, struct plot_info *pi, int cur, int pressure)
+static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t 
*segment, struct plot_info *pi, int cur)
 { // cur = index to pi->entry corresponding to t_end of segment;
        struct pr_interpolate_struct interpolate;
        int i;
@@ -194,19 +194,11 @@ static struct pr_interpolate_struct 
get_pr_interpolate_data(pr_track_t *segment,
                if (entry->sec == segment->t_start) {
                        interpolate.acc_pressure_time = 0;
                        interpolate.pressure_time = 0;
-                       if (pressure)
-                               interpolate.start = pressure;
                        continue;
                }
                if (i < cur) {
-                       if (pressure) {
-                               interpolate.start = pressure;
-                               interpolate.acc_pressure_time = 0;
-                               interpolate.pressure_time = 0;
-                       } else {
-                               interpolate.acc_pressure_time += 
entry->pressure_time;
-                               interpolate.pressure_time += 
entry->pressure_time;
-                       }
+                       interpolate.acc_pressure_time += entry->pressure_time;
+                       interpolate.pressure_time += entry->pressure_time;
                        continue;
                }
                if (i == cur) {
@@ -215,10 +207,6 @@ static struct pr_interpolate_struct 
get_pr_interpolate_data(pr_track_t *segment,
                        continue;
                }
                interpolate.pressure_time += entry->pressure_time;
-               if (pressure) {
-                       interpolate.end = pressure;
-                       break;
-               }
        }
        return interpolate;
 }
@@ -299,7 +287,7 @@ static void fill_missing_tank_pressures(struct dive *dive, 
struct plot_info *pi,
                }
 
                // If there is a valid segment but no tank pressure ..
-               interpolate = get_pr_interpolate_data(segment, pi, i, 
pressure); // Set up an interpolation structure
+               interpolate = get_pr_interpolate_data(segment, pi, i); // Set 
up an interpolation structure
                if(dive->cylinder[cyl].cylinder_use == OC_GAS) {
 
                        /* if this segment has pressure_time, then calculate a 
new interpolated pressure */
-- 
2.7.0.170.ge572fef

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to