From e5c560e8baac2b0ca218fd2da1c4437125fd5715 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 28 Nov 2020 22:27:58 +0800 Subject: [PATCH] simplify code, format makefile (#233) --- core/collection/rollingwindow.go | 7 ++++--- tools/goctl/Makefile | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/collection/rollingwindow.go b/core/collection/rollingwindow.go index 9f0db0a5..804fda3e 100644 --- a/core/collection/rollingwindow.go +++ b/core/collection/rollingwindow.go @@ -76,22 +76,23 @@ func (rw *RollingWindow) updateOffset() { span := rw.span() if span > 0 { offset := rw.offset - // reset expired buckets start := offset + 1 steps := start + span - offset = (offset + span) % rw.size 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 + + rw.offset = (offset + span) % rw.size rw.lastTime = timex.Now() } } diff --git a/tools/goctl/Makefile b/tools/goctl/Makefile index 8581c31d..b5808826 100644 --- a/tools/goctl/Makefile +++ b/tools/goctl/Makefile @@ -2,13 +2,13 @@ version := $(shell /bin/date "+%Y-%m-%d %H:%M") build: go build -ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(version)'" goctl.go - $(if $(shell command -v upx),upx goctl) + $(if $(shell command -v upx), upx goctl) mac: GOOS=darwin go build -ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(version)'" -o goctl-darwin goctl.go - $(if $(shell command -v upx),upx goctl-darwin) + $(if $(shell command -v upx), upx goctl-darwin) win: GOOS=windows go build -ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(version)'" -o goctl.exe goctl.go - $(if $(shell command -v upx),upx goctl.exe) + $(if $(shell command -v upx), upx goctl.exe) linux: GOOS=linux go build -ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(version)'" -o goctl-linux goctl.go - $(if $(shell command -v upx),upx goctl-linux) + $(if $(shell command -v upx), upx goctl-linux)