Reverse the average rate history early-return logic to make it easier to understand

This commit is contained in:
Andrew Wood
2023-07-16 20:49:59 +01:00
parent e8c0b6717f
commit 62b5ac26df
+11 -3
View File
@@ -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)