DecayingSample::decay must always return with the time current.

This commit is contained in:
David Schwartz
2013-10-29 14:46:22 -07:00
parent 4ddadb8792
commit 4eebea91d3

View File

@@ -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;
if (m_value != value_type())
{
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)
{
m_value = value_type();
return;
}
else
{
while (n--)
m_value -= (m_value + Window - 1) / Window;
}
}
m_when = now;
}