Skip to content

Commit

Permalink
Use calculateTimeIdx to calculate array idx in LeapArray#getPreviousW…
Browse files Browse the repository at this point in the history
…indow (#723)

* also some code cleanup
  • Loading branch information
kexianjun authored and sczyh30 committed Jun 5, 2019
1 parent ee38587 commit 0176f0e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ public void reset() {

@Override
public long totalRequest() {
long totalRequest = rollingCounterInMinute.pass() + rollingCounterInMinute.block();
return totalRequest;
return rollingCounterInMinute.pass() + rollingCounterInMinute.block();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ public WindowWrap<T> getPreviousWindow(long timeMillis) {
if (timeMillis < 0) {
return null;
}
long timeId = (timeMillis - windowLengthInMs) / windowLengthInMs;
int idx = (int)(timeId % array.length());
int idx = calculateTimeIdx(timeMillis - windowLengthInMs);
timeMillis = timeMillis - windowLengthInMs;
WindowWrap<T> wrap = array.get(idx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ public void debug() {

@Override
public long previousWindowBlock() {
WindowWrap<MetricBucket> wrap = data.currentWindow();
wrap = data.getPreviousWindow();
data.currentWindow();
WindowWrap<MetricBucket> wrap = data.getPreviousWindow();
if (wrap == null) {
return 0;
}
Expand All @@ -244,8 +244,8 @@ public long previousWindowBlock() {

@Override
public long previousWindowPass() {
WindowWrap<MetricBucket> wrap = data.currentWindow();
wrap = data.getPreviousWindow();
data.currentWindow();
WindowWrap<MetricBucket> wrap = data.getPreviousWindow();
if (wrap == null) {
return 0;
}
Expand Down

0 comments on commit 0176f0e

Please sign in to comment.