From 5d5af6e9268c5f63eeffae2df2e86bf8f9b9728e Mon Sep 17 00:00:00 2001 From: Tessa Nordgren Date: Fri, 18 Feb 2022 12:09:52 -0800 Subject: [PATCH] minor improvements from static code analysis --- go.sum | 1 + queue_test.go | 5 +---- scheduler.go | 5 +---- stats.go | 2 +- uintslice.go | 5 +---- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/go.sum b/go.sum index ce9e261..5594bca 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/eapache/queue.v1 v1.1.0 h1:EldqoJEGtXYiVCMRo2C9mePO2UUGnYn2+qLmlQSqPdc= gopkg.in/eapache/queue.v1 v1.1.0/go.mod h1:wNtmx1/O7kZSR9zNT1TTOJ7GLpm3Vn7srzlfylFbQwU= diff --git a/queue_test.go b/queue_test.go index 63dc120..5f497cf 100644 --- a/queue_test.go +++ b/queue_test.go @@ -4,16 +4,13 @@ import ( "runtime" "sync" "testing" - "time" ) var testQ = NewQueue() func testAdd(n int) { for i := 0; i < n; i++ { - testQ.Add(func() { - time.Sleep(1) - }) + testQ.Add(func() {}) } } diff --git a/scheduler.go b/scheduler.go index 88f68e4..cd560ba 100644 --- a/scheduler.go +++ b/scheduler.go @@ -33,10 +33,7 @@ func SimpleScheduler(tq *TaskQueue) bool { queued++ } } - if queued > 0 { - return true - } - return false + return (queued > 0) } // TimeSliceScheduler attempts to give tasks a fair share of the Stats() diff --git a/stats.go b/stats.go index 988bd0a..96867bb 100644 --- a/stats.go +++ b/stats.go @@ -74,7 +74,7 @@ func (s *Stat) Start() (start time.Time) { // This will fluctuate between 90-100% of the window size set when the state // was created, as internal buckets roll over. func (s *Stat) Duration() time.Duration { - return time.Now().Sub(s.Start()) + return time.Since(s.Start()) } // Rate returns the flow rate of this counter, which is the current rolling diff --git a/uintslice.go b/uintslice.go index 95f87ff..c7131a7 100644 --- a/uintslice.go +++ b/uintslice.go @@ -11,10 +11,7 @@ func (list UIntSlice) Len() int { // Less helps fulfill sort.Interface. func (list UIntSlice) Less(i, j int) bool { - if list[i] <= list[j] { - return true - } - return false + return list[i] <= list[j] } // Swap helps fulfill sort.Interface