Skip to content

Commit

Permalink
Remove extra calls to map.get in sumByDoubleFunction and sumByFloatFu…
Browse files Browse the repository at this point in the history
…nction.

Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
  • Loading branch information
donraab committed Sep 14, 2020
1 parent c9c84ba commit de17f10
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ public MutableObjectDoubleMap<V> value(MutableObjectDoubleMap<V> map, T each)
V groupKey = groupBy.valueOf(each);
double compensation = this.compensation.getIfAbsent(groupKey, 0.0d);
double adjustedValue = function.floatValueOf(each) - compensation;
double nextSum = map.get(groupKey) + adjustedValue;
this.compensation.put(groupKey, nextSum - map.get(groupKey) - adjustedValue);
double currentSum = map.get(groupKey);
double nextSum = currentSum + adjustedValue;
this.compensation.put(groupKey, nextSum - currentSum - adjustedValue);
map.put(groupKey, nextSum);
return map;
}
Expand Down Expand Up @@ -176,8 +177,9 @@ public MutableObjectDoubleMap<V> value(MutableObjectDoubleMap<V> map, T each)
V groupKey = groupBy.valueOf(each);
double compensation = this.compensation.getIfAbsent(groupKey, 0.0d);
double adjustedValue = function.doubleValueOf(each) - compensation;
double nextSum = map.get(groupKey) + adjustedValue;
this.compensation.put(groupKey, nextSum - map.get(groupKey) - adjustedValue);
double currentSum = map.get(groupKey);
double nextSum = currentSum + adjustedValue;
this.compensation.put(groupKey, nextSum - currentSum - adjustedValue);
map.put(groupKey, nextSum);
return map;
}
Expand Down

0 comments on commit de17f10

Please sign in to comment.