From 4b5c2de37672e0dea4dacf513defe028a257f70a Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sun, 29 Nov 2020 12:41:42 +0800 Subject: [PATCH] simplify code (#234) * simplify code, format makefile * simplify code --- core/collection/rollingwindow.go | 42 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/core/collection/rollingwindow.go b/core/collection/rollingwindow.go index 804fda3e..c9f45aaf 100644 --- a/core/collection/rollingwindow.go +++ b/core/collection/rollingwindow.go @@ -74,27 +74,29 @@ func (rw *RollingWindow) span() int { func (rw *RollingWindow) updateOffset() { span := rw.span() - if span > 0 { - offset := rw.offset - start := offset + 1 - steps := start + span - var remainder int - if steps > rw.size { - remainder = steps - rw.size - steps = rw.size - } - - // reset expired buckets - for i := start; i < steps; i++ { - rw.win.resetBucket(i) - } - for i := 0; i < remainder; i++ { - rw.win.resetBucket(i) - } - - rw.offset = (offset + span) % rw.size - rw.lastTime = timex.Now() + if span <= 0 { + return } + + offset := rw.offset + start := offset + 1 + steps := start + span + var remainder int + if steps > rw.size { + remainder = steps - rw.size + steps = rw.size + } + + // reset expired buckets + for i := start; i < steps; i++ { + rw.win.resetBucket(i) + } + for i := 0; i < remainder; i++ { + rw.win.resetBucket(i) + } + + rw.offset = (offset + span) % rw.size + rw.lastTime = timex.Now() } type Bucket struct {