diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-07-06 15:34:31 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-07-06 11:23:35 -0700 |
commit | ae60fdf815d1febe36b5f43642a28afbaf84362b (patch) | |
tree | 20e33d82b358bab3fb582969c455e188683c1cf4 | |
parent | 69be1e23f231081e6bad98903c10782faf5104a7 (diff) | |
download | subsurface-ae60fdf815d1febe36b5f43642a28afbaf84362b.tar.gz |
Cleanup: call calculate_max_limits_new() in create_plot_info_new()
All callers of create_plot_info_new() called calculate_max_limits_new()
a line before. Thus, simply call the latter in the former.
This allows us to automatically free the plot data in create_plot_info_new().
The old code overwrote the corresponding field with NULL.
As a side-effect, this removes a bogus static variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/profile.c | 23 | ||||
-rw-r--r-- | core/profile.h | 1 | ||||
-rw-r--r-- | core/save-profiledata.c | 2 | ||||
-rw-r--r-- | profile-widget/profilewidget2.cpp | 3 |
4 files changed, 12 insertions, 17 deletions
diff --git a/core/profile.c b/core/profile.c index 5f8be02ac..1492949c4 100644 --- a/core/profile.c +++ b/core/profile.c @@ -398,11 +398,10 @@ static void check_setpoint_events(const struct dive *dive, struct divecomputer * } -struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *given_dc) +static void calculate_max_limits_new(struct dive *dive, struct divecomputer *given_dc, struct plot_info *pi) { struct divecomputer *dc = &(dive->dc); bool seen = false; - static struct plot_info pi; int maxdepth = dive->maxdepth.mm; int maxtime = 0; int maxpressure = 0, minpressure = INT_MAX; @@ -478,16 +477,15 @@ struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer if (minhr > maxhr) minhr = maxhr; - memset(&pi, 0, sizeof(pi)); - pi.maxdepth = maxdepth; - pi.maxtime = maxtime; - pi.maxpressure = maxpressure; - pi.minpressure = minpressure; - pi.minhr = minhr; - pi.maxhr = maxhr; - pi.mintemp = mintemp; - pi.maxtemp = maxtemp; - return pi; + memset(pi, 0, sizeof(*pi)); + pi->maxdepth = maxdepth; + pi->maxtime = maxtime; + pi->maxpressure = maxpressure; + pi->minpressure = minpressure; + pi->minhr = minhr; + pi->maxhr = maxhr; + pi->mintemp = mintemp; + pi->maxtemp = maxtemp; } /* copy the previous entry (we know this exists), update time and depth @@ -1337,6 +1335,7 @@ void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plo UNUSED(planner_ds); #endif free_plot_info_data(pi); + calculate_max_limits_new(dive, dc, pi); get_dive_gas(dive, &o2, &he, &o2max); if (dc->divemode == FREEDIVE){ pi->dive_type = FREEDIVE; diff --git a/core/profile.h b/core/profile.h index 125e349a8..d9a0ed731 100644 --- a/core/profile.h +++ b/core/profile.h @@ -73,7 +73,6 @@ struct ev_select { bool plot_ev; }; -struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *given_dc); void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int bufsize, int sum); struct plot_info *analyze_plot_info(struct plot_info *pi); void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, struct deco_state *planner_ds); diff --git a/core/save-profiledata.c b/core/save-profiledata.c index d999d4b49..a88ce8ae1 100644 --- a/core/save-profiledata.c +++ b/core/save-profiledata.c @@ -202,7 +202,6 @@ static void save_profiles_buffer(struct membuffer *b, bool select_only) for_each_dive(i, dive) { if (select_only && !dive->selected) continue; - pi = calculate_max_limits_new(dive, &dive->dc); create_plot_info_new(dive, &dive->dc, &pi, false, planner_deco_state); put_headers(b); put_format(b, "\n"); @@ -221,7 +220,6 @@ void save_subtitles_buffer(struct membuffer *b, struct dive *dive, int offset, i struct plot_info pi; struct deco_state *planner_deco_state = NULL; - pi = calculate_max_limits_new(dive, &dive->dc); create_plot_info_new(dive, &dive->dc, &pi, false, planner_deco_state); put_format(b, "[Script Info]\n"); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index f377eeb8e..ca6ce3950 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -636,8 +636,7 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict * shown. */ - free_plot_info_data(&plotInfo); - plotInfo = calculate_max_limits_new(&displayed_dive, currentdc); + // create_plot_info_new() automatically frees old plot data #ifndef SUBSURFACE_MOBILE create_plot_info_new(&displayed_dive, currentdc, &plotInfo, !shouldCalculateMaxDepth, &DivePlannerPointsModel::instance()->final_deco_state); #else |