Skip to content

Commit 6a5a283

Browse files
authored
Use builtin min and max functions (#7478)
* Use builtin min and max functions Go added builtin min and max functions in 1.21. This commit removes existing functions and uses the built-ins in stead. * Revert gofmt changes
1 parent 90caeb3 commit 6a5a283

File tree

9 files changed

+2
-65
lines changed

9 files changed

+2
-65
lines changed

balancer/rls/internal/adaptive/lookback.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,3 @@ func (l *lookback) advance(t time.Time) int64 {
8282
l.head = nh
8383
return nh
8484
}
85-
86-
func min(x int64, y int64) int64 {
87-
if x < y {
88-
return x
89-
}
90-
return y
91-
}

benchmark/stats/stats.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,3 @@ func (s *Stats) dump(result *BenchResults) {
494494
b.WriteString(fmt.Sprintf("Number of responses: %v\tResponse throughput: %v bit/s\n", resp, result.Data.RespT))
495495
fmt.Println(b.String())
496496
}
497-
498-
func max(a, b int64) int64 {
499-
if a > b {
500-
return a
501-
}
502-
return b
503-
}

credentials/alts/internal/conn/record.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,3 @@ func (p *conn) Write(b []byte) (n int, err error) {
266266
}
267267
return n, nil
268268
}
269-
270-
func min(a, b int) int {
271-
if a < b {
272-
return a
273-
}
274-
return b
275-
}

internal/channelz/channelmap.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,6 @@ func copyMap(m map[int64]string) map[int64]string {
234234
return n
235235
}
236236

237-
func min(a, b int) int {
238-
if a < b {
239-
return a
240-
}
241-
return b
242-
}
243-
244237
func (c *channelMap) getTopChannels(id int64, maxResults int) ([]*Channel, bool) {
245238
if maxResults <= 0 {
246239
maxResults = EntriesPerPage

internal/transport/controlbuf.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,10 +1017,3 @@ func (l *loopyWriter) processData() (bool, error) {
10171017
}
10181018
return false, nil
10191019
}
1020-
1021-
func min(a, b int) int {
1022-
if a < b {
1023-
return a
1024-
}
1025-
return b
1026-
}

internal/transport/http2_client.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,13 +1684,6 @@ func (t *http2Client) reader(errCh chan<- error) {
16841684
}
16851685
}
16861686

1687-
func minTime(a, b time.Duration) time.Duration {
1688-
if a < b {
1689-
return a
1690-
}
1691-
return b
1692-
}
1693-
16941687
// keepalive running in a separate goroutine makes sure the connection is alive by sending pings.
16951688
func (t *http2Client) keepalive() {
16961689
p := &ping{data: [8]byte{}}
@@ -1758,7 +1751,7 @@ func (t *http2Client) keepalive() {
17581751
// timeoutLeft. This will ensure that we wait only for kp.Time
17591752
// before sending out the next ping (for cases where the ping is
17601753
// acked).
1761-
sleepDuration := minTime(t.kp.Time, timeoutLeft)
1754+
sleepDuration := min(t.kp.Time, timeoutLeft)
17621755
timeoutLeft -= sleepDuration
17631756
timer.Reset(sleepDuration)
17641757
case <-t.ctx.Done():

internal/transport/http2_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ func (t *http2Server) keepalive() {
12251225
// timeoutLeft. This will ensure that we wait only for kp.Time
12261226
// before sending out the next ping (for cases where the ping is
12271227
// acked).
1228-
sleepDuration := minTime(t.kp.Time, kpTimeoutLeft)
1228+
sleepDuration := min(t.kp.Time, kpTimeoutLeft)
12291229
kpTimeoutLeft -= sleepDuration
12301230
kpTimer.Reset(sleepDuration)
12311231
case <-t.done:

test/end2end_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,13 +4743,6 @@ type windowSizeConfig struct {
47434743
clientConn int32
47444744
}
47454745

4746-
func max(a, b int32) int32 {
4747-
if a > b {
4748-
return a
4749-
}
4750-
return b
4751-
}
4752-
47534746
func (s) TestConfigurableWindowSizeWithLargeWindow(t *testing.T) {
47544747
wc := windowSizeConfig{
47554748
serverStream: 8 * 1024 * 1024,

xds/internal/balancer/outlierdetection/balancer.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -592,20 +592,6 @@ func (b *outlierDetectionBalancer) Target() string {
592592
return b.cc.Target()
593593
}
594594

595-
func max(x, y time.Duration) time.Duration {
596-
if x < y {
597-
return y
598-
}
599-
return x
600-
}
601-
602-
func min(x, y time.Duration) time.Duration {
603-
if x < y {
604-
return x
605-
}
606-
return y
607-
}
608-
609595
// handleSubConnUpdate stores the recent state and forward the update
610596
// if the SubConn is not ejected.
611597
func (b *outlierDetectionBalancer) handleSubConnUpdate(u *scUpdate) {

0 commit comments

Comments
 (0)