optimization (#221)

master
xuezonggui 4 years ago committed by GitHub
parent 2dfecda465
commit bed494d904
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -79,6 +79,7 @@ func (rw *RollingWindow) updateOffset() {
// reset expired buckets // reset expired buckets
start := offset + 1 start := offset + 1
steps := start + span steps := start + span
offset = (offset + span) % rw.size
var remainder int var remainder int
if steps > rw.size { if steps > rw.size {
remainder = steps - rw.size remainder = steps - rw.size
@ -86,11 +87,9 @@ func (rw *RollingWindow) updateOffset() {
} }
for i := start; i < steps; i++ { for i := start; i < steps; i++ {
rw.win.resetBucket(i) rw.win.resetBucket(i)
offset = i
} }
for i := 0; i < remainder; i++ { for i := 0; i < remainder; i++ {
rw.win.resetBucket(i) rw.win.resetBucket(i)
offset = i
} }
rw.offset = offset rw.offset = offset
rw.lastTime = timex.Now() rw.lastTime = timex.Now()

Loading…
Cancel
Save