From efc5ee8e197b3e4606f963719a02e6d3684d29fa Mon Sep 17 00:00:00 2001 From: Roger Ng Date: Wed, 12 Mar 2025 16:56:49 +0000 Subject: [PATCH] Modernize if statement using `max` --- internal/hammer/loadtest/throttle.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/internal/hammer/loadtest/throttle.go b/internal/hammer/loadtest/throttle.go index 502e0281..5c1d67a3 100644 --- a/internal/hammer/loadtest/throttle.go +++ b/internal/hammer/loadtest/throttle.go @@ -40,10 +40,7 @@ func (t *Throttle) Increase() { t.mu.Lock() defer t.mu.Unlock() tokenCount := t.opsPerSecond - delta := float64(tokenCount) * 0.1 - if delta < 1 { - delta = 1 - } + delta := max(float64(tokenCount)*0.1, 1) t.opsPerSecond = tokenCount + int(delta) } @@ -54,10 +51,7 @@ func (t *Throttle) Decrease() { if tokenCount <= 1 { return } - delta := float64(tokenCount) * 0.1 - if delta < 1 { - delta = 1 - } + delta := max(float64(tokenCount)*0.1, 1) t.opsPerSecond = tokenCount - int(delta) }