From 4eebea91d32be923480818deb1c5d260d6029248 Mon Sep 17 00:00:00 2001 From: David Schwartz Date: Tue, 29 Oct 2013 14:46:22 -0700 Subject: [PATCH] DecayingSample::decay must always return with the time current. --- src/ripple/resource/impl/DecayingSample.h | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/ripple/resource/impl/DecayingSample.h b/src/ripple/resource/impl/DecayingSample.h index 4b603ca6cb..192b59bed9 100644 --- a/src/ripple/resource/impl/DecayingSample.h +++ b/src/ripple/resource/impl/DecayingSample.h @@ -63,25 +63,24 @@ private: // Apply exponential decay based on the specified time. void decay (elapsed_type now) { - if (m_value == value_type()) + if (now == m_when) return; - elapsed_type n (now - m_when); - - if (n == 0) - return; - - // A span larger than four times the window decays the - // value to an insignificant amount so just reset it. - // - if (n > 4 * Window) + if (m_value != value_type()) { - m_value = value_type(); - return; - } + elapsed_type n (now - m_when); - while (n--) - m_value -= (m_value + Window - 1) / Window; + // A span larger than four times the window decays the + // value to an insignificant amount so just reset it. + // + if (n > 4 * Window) + m_value = value_type(); + else + { + while (n--) + m_value -= (m_value + Window - 1) / Window; + } + } m_when = now; }