rate: simplify function advance only returns new Tokens to caller
Change the advance method to stop returning the newT result,
because it is always the same as the t argument.
Change-Id: Ib04017715d9f38f4ef6b908cb3d3b09af01b50b7
GitHub-Last-Rev: 1bc7316b96ca2d8e94f64f30db74536fe2fbe58f
GitHub-Pull-Request: golang/time#24
Reviewed-on: https://go-review.googlesource.com/c/time/+/645995
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/rate/rate.go b/rate/rate.go
index ec5f0cd..794b2e3 100644
--- a/rate/rate.go
+++ b/rate/rate.go
@@ -85,7 +85,7 @@
// TokensAt returns the number of tokens available at time t.
func (lim *Limiter) TokensAt(t time.Time) float64 {
lim.mu.Lock()
- _, tokens := lim.advance(t) // does not mutate lim
+ tokens := lim.advance(t) // does not mutate lim
lim.mu.Unlock()
return tokens
}
@@ -186,7 +186,7 @@
return
}
// advance time to now
- t, tokens := r.lim.advance(t)
+ tokens := r.lim.advance(t)
// calculate new number of tokens
tokens += restoreTokens
if burst := float64(r.lim.burst); tokens > burst {
@@ -307,7 +307,7 @@
lim.mu.Lock()
defer lim.mu.Unlock()
- t, tokens := lim.advance(t)
+ tokens := lim.advance(t)
lim.last = t
lim.tokens = tokens
@@ -324,7 +324,7 @@
lim.mu.Lock()
defer lim.mu.Unlock()
- t, tokens := lim.advance(t)
+ tokens := lim.advance(t)
lim.last = t
lim.tokens = tokens
@@ -347,7 +347,7 @@
}
}
- t, tokens := lim.advance(t)
+ tokens := lim.advance(t)
// Calculate the remaining number of tokens resulting from the request.
tokens -= float64(n)
@@ -380,10 +380,11 @@
return r
}
-// advance calculates and returns an updated state for lim resulting from the passage of time.
+// advance calculates and returns an updated number of tokens for lim
+// resulting from the passage of time.
// lim is not changed.
// advance requires that lim.mu is held.
-func (lim *Limiter) advance(t time.Time) (newT time.Time, newTokens float64) {
+func (lim *Limiter) advance(t time.Time) (newTokens float64) {
last := lim.last
if t.Before(last) {
last = t
@@ -396,7 +397,7 @@
if burst := float64(lim.burst); tokens > burst {
tokens = burst
}
- return t, tokens
+ return tokens
}
// durationFromTokens is a unit conversion function from the number of tokens to the duration