[PATCH 3/3] Use the new get_o2()/get_he() helper functions more widely

Linus Torvalds torvalds at linux-foundation.org
Thu Mar 28 10:17:38 PDT 2013


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Thu, 28 Mar 2013 10:06:43 -0700
Subject: [PATCH 3/3] Use the new get_o2()/get_he() helper functions more widely

They do the "02=0 means air" thing autmatically, and make for less
typing.  So use them more widely in places that looked up the o2 and he
permille values of a gasmix.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This is just a tiny cleanup patch, just using the helper functions I 
introduced in the previous commit more widely.

 deco.c       | 6 +++---
 dive.c       | 9 ++++-----
 profile.c    | 4 ++--
 statistics.c | 6 +++---
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/deco.c b/deco.c
index 87899b5eeb04..ab3b4289392b 100644
--- a/deco.c
+++ b/deco.c
@@ -130,9 +130,9 @@ static double tissue_tolerance_calc(const struct dive *dive)
 double add_segment(double pressure, const struct gasmix *gasmix, int period_in_seconds, int ccpo2, const struct dive *dive)
 {
 	int ci;
-	int fo2 = gasmix->o2.permille ? gasmix->o2.permille : O2_IN_AIR;
-	double ppn2 = (pressure - WV_PRESSURE) * (1000 - fo2 - gasmix->he.permille) / 1000.0;
-	double pphe = (pressure - WV_PRESSURE) * gasmix->he.permille / 1000.0;
+	int fo2 = get_o2(gasmix), fhe = get_he(gasmix);
+	double ppn2 = (pressure - WV_PRESSURE) * (1000 - fo2 - fhe) / 1000.0;
+	double pphe = (pressure - WV_PRESSURE) * fhe / 1000.0;
 
 #if GF_LOW_AT_MAXDEPTH
 	if (pressure > gf_low_pressure_this_dive)
diff --git a/dive.c b/dive.c
index a43c1afc4292..46121848c6ce 100644
--- a/dive.c
+++ b/dive.c
@@ -1021,9 +1021,8 @@ static void merge_weightsystem_info(weightsystem_t *res, weightsystem_t *a, weig
 
 static int gasmix_distance(const struct gasmix *a, const struct gasmix *b)
 {
-	int a_o2 = a->o2.permille ? : O2_IN_AIR;
-	int b_o2 = b->o2.permille ? : O2_IN_AIR;
-	int a_he = a->he.permille, b_he = b->he.permille;
+	int a_o2 = get_o2(a), b_o2 = get_o2(b);
+	int a_he = get_he(a), b_he = get_he(b);
 	int delta_o2 = a_o2 - b_o2, delta_he = a_he - b_he;
 
 	delta_he = delta_he*delta_he;
@@ -1064,8 +1063,8 @@ static void add_initial_gaschange(struct dive *dive, struct divecomputer *dc)
 		return;
 
 	/* Old starting gas mix */
-	o2 = dive->cylinder[0].gasmix.o2.permille ? : O2_IN_AIR;
-	he = dive->cylinder[0].gasmix.o2.permille;
+	o2 = get_o2(&dive->cylinder[0].gasmix);
+	he = get_he(&dive->cylinder[0].gasmix);
 	o2 = (o2 + 5) / 10;
 	he = (he + 5) / 10;
 	value = o2 + (he << 16);
diff --git a/profile.c b/profile.c
index 6be4b13ef16c..59c6485a95f8 100644
--- a/profile.c
+++ b/profile.c
@@ -1877,8 +1877,8 @@ static void calculate_deco_information(struct dive *dive, struct divecomputer *d
 		int cylinderindex = entry->cylinderindex;
 
 		amb_pressure = depth_to_mbar(entry->depth, dive) / 1000.0;
-		fo2 = dive->cylinder[cylinderindex].gasmix.o2.permille ? : O2_IN_AIR;
-		fhe = dive->cylinder[cylinderindex].gasmix.he.permille;
+		fo2 = get_o2(&dive->cylinder[cylinderindex].gasmix);
+		fhe = get_he(&dive->cylinder[cylinderindex].gasmix);
 		double ratio = (double)fhe / (1000.0 - fo2);
 
 		if (entry->po2) {
diff --git a/statistics.c b/statistics.c
index 0ce8f6afebd7..a39799a08d04 100644
--- a/statistics.c
+++ b/statistics.c
@@ -610,13 +610,13 @@ static void show_single_dive_stats(struct dive *dive)
 		end = cyl->end.mbar ?cyl->sample_end : cyl->sample_end;
 		if (!cylinder_none(cyl)) {
 			/* 0% O2 strangely means air, so 21% - I don't like that at all */
-			int o2 = cyl->gasmix.o2.permille ? : O2_IN_AIR;
+			int o2 = get_o2(&cyl->gasmix);
+			int he = get_he(&cyl->gasmix);
 			if (offset > 0) {
 				snprintf(buf+offset, 80-offset, ", ");
 				offset += 2;
 			}
-			snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10,
-				(cyl->gasmix.he.permille + 5) / 10);
+			snprintf(buf+offset, 80-offset, "%d/%d", (o2 + 5) / 10, (he + 5) / 10);
 			offset = strlen(buf);
 		}
 		/* and if we have size, start and end pressure, we can
-- 
1.8.2.230.g2bba2f0



More information about the subsurface mailing list