summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-09-29 19:55:59 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-09-29 19:55:59 +0000
commitf76d573a9908d06131e3ff3ca8fcf397114fdd57 (patch)
tree51e7e136470f9377d364c585273b12b81b885cca
parent7deb477d387ff85bcc049f728ca68bf98aa60fc4 (diff)
parent41f5663f32acaff38a554883a396b6a2589e80b1 (diff)
Merge "Return zero delta when delta is not computed"
-rw-r--r--libs/battery/MultiStateCounter.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/libs/battery/MultiStateCounter.h b/libs/battery/MultiStateCounter.h
index 112fb85051..03e1f2a022 100644
--- a/libs/battery/MultiStateCounter.h
+++ b/libs/battery/MultiStateCounter.h
@@ -168,6 +168,8 @@ void MultiStateCounter<T>::setValue(state_t state, const T& value) {
template <class T>
const T& MultiStateCounter<T>::updateValue(const T& value, time_t timestamp) {
+ T* returnValue = &emptyValue;
+
// If the counter is disabled, we ignore the update, except when the counter got disabled after
// the previous update, in which case we still need to pick up the residual delta.
if (isEnabled || lastUpdateTimestamp < lastStateChangeTimestamp) {
@@ -178,6 +180,7 @@ const T& MultiStateCounter<T>::updateValue(const T& value, time_t timestamp) {
if (lastUpdateTimestamp >= 0) {
if (timestamp > lastUpdateTimestamp) {
if (delta(lastValue, value, &deltaValue)) {
+ returnValue = &deltaValue;
time_t timeSinceUpdate = timestamp - lastUpdateTimestamp;
for (int i = 0; i < stateCount; i++) {
time_t timeInState = states[i].timeInStateSinceUpdate;
@@ -201,7 +204,7 @@ const T& MultiStateCounter<T>::updateValue(const T& value, time_t timestamp) {
}
lastValue = value;
lastUpdateTimestamp = timestamp;
- return deltaValue;
+ return *returnValue;
}
template <class T>