From 62b5ac26dfd04e3550c3807765b44ee9d4083593 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 16 Jul 2023 20:49:59 +0100 Subject: [PATCH] Reverse the average rate history early-return logic to make it easier to understand --- src/pv/display.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pv/display.c b/src/pv/display.c index b267154..9e3a576 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -446,11 +446,19 @@ static void update_history_avg_rate(pvstate_t state, long long total_bytes, last_elapsed = state->history[last].elapsed_sec; - if (!(last_elapsed == 0.0 || /* Empty */ - elapsed_sec > last_elapsed + state->history_interval)) + /* + * Do nothing if this is not the first call but not enough time has + * elapsed since the previous call yet. + */ + if ((last_elapsed > 0.0) + && (elapsed_sec < (last_elapsed + state->history_interval))) return; - if (last_elapsed) { /* Not empty, add new entry in circular buffer */ + /* + * This is not the first call, so add a new entry to the circular + * buffer. + */ + if (last_elapsed > 0.0) { int len = state->history_len; state->history_last = last = (last + 1) % len; if (last == first)