From 50c573910b7d32b937c75738c0bc1e5fb357e603 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Fri, 8 Jun 2018 15:02:17 -0700 Subject: [PATCH] DecayCounter: remove unnecessary delta member We can just add/sub to val directly (especially now that decay can be called on a const DecayCounter). Signed-off-by: Patrick Donnelly --- src/common/DecayCounter.cc | 17 +++++++++-------- src/common/DecayCounter.h | 10 ++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/common/DecayCounter.cc b/src/common/DecayCounter.cc index b06267c11ed..1144daaf068 100644 --- a/src/common/DecayCounter.cc +++ b/src/common/DecayCounter.cc @@ -19,16 +19,16 @@ void DecayCounter::encode(bufferlist& bl) const { - ENCODE_START(4, 4, bl); + decay(rate); + ENCODE_START(5, 4, bl); encode(val, bl); - encode(delta, bl); encode(vel, bl); ENCODE_FINISH(bl); } void DecayCounter::decode(bufferlist::const_iterator &p) { - DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, p); + DECODE_START_LEGACY_COMPAT_LEN(5, 4, 4, p); if (struct_v < 2) { double half_life = 0.0; decode(half_life, p); @@ -38,7 +38,11 @@ void DecayCounter::decode(bufferlist::const_iterator &p) decode(k, p); } decode(val, p); - decode(delta, p); + if (struct_v < 5) { + double delta; + decode(delta, p); + val += delta; + } decode(vel, p); last_decay = clock::now(); DECODE_FINISH(p); @@ -48,7 +52,6 @@ void DecayCounter::dump(Formatter *f) const { decay(rate); f->dump_float("value", val); - f->dump_float("delta", delta); f->dump_float("velocity", vel); } @@ -56,7 +59,6 @@ void DecayCounter::generate_test_instances(std::list& ls) { DecayCounter *counter = new DecayCounter(); counter->val = 3.0; - counter->delta = 2.0; counter->vel = 1.0; ls.push_back(counter); counter = new DecayCounter(); @@ -72,7 +74,7 @@ void DecayCounter::decay(const DecayRate &rate) const return; /* no need to decay for small differences */ // calculate new value - double newval = (val+delta) * exp(el * rate.k); + double newval = val * exp(el * rate.k); if (newval < .01) { newval = 0.0; } @@ -82,7 +84,6 @@ void DecayCounter::decay(const DecayRate &rate) const vel *= exp(el * rate.k); val = newval; - delta = 0; last_decay = now; } } diff --git a/src/common/DecayCounter.h b/src/common/DecayCounter.h index a3f47653fe0..47ec0670118 100644 --- a/src/common/DecayCounter.h +++ b/src/common/DecayCounter.h @@ -68,7 +68,7 @@ public: double get() const { decay(rate); - return val+delta; + return val; } double get_last() const { @@ -89,8 +89,8 @@ public: double hit(double v = 1.0) { decay(rate); - delta += v; - return val+delta; + val += v; + return val; } void adjust(double a) { @@ -102,7 +102,6 @@ public: void scale(double f) { val *= f; - delta *= f; vel *= f; } @@ -112,7 +111,7 @@ public: void reset() { last_decay = clock::now(); - val = delta = 0; + val = vel = 0; } protected: @@ -120,7 +119,6 @@ protected: private: mutable double val = 0.0; // value - mutable double delta = 0.0; // delta since last decay mutable double vel = 0.0; // recent velocity mutable time last_decay = clock::zero(); // time of last decay DecayRate rate;