Skip to content

Commit

Permalink
Use builtin min and max functions (grpc#7478)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jhalterman authored Aug 20, 2024
1 parent 90caeb3 commit 6a5a283
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 65 deletions.
7 changes: 0 additions & 7 deletions balancer/rls/internal/adaptive/lookback.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,3 @@ func (l *lookback) advance(t time.Time) int64 {
l.head = nh
return nh
}

func min(x int64, y int64) int64 {
if x < y {
return x
}
return y
}
7 changes: 0 additions & 7 deletions benchmark/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,3 @@ func (s *Stats) dump(result *BenchResults) {
b.WriteString(fmt.Sprintf("Number of responses: %v\tResponse throughput: %v bit/s\n", resp, result.Data.RespT))
fmt.Println(b.String())
}

func max(a, b int64) int64 {
if a > b {
return a
}
return b
}
7 changes: 0 additions & 7 deletions credentials/alts/internal/conn/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,3 @@ func (p *conn) Write(b []byte) (n int, err error) {
}
return n, nil
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
7 changes: 0 additions & 7 deletions internal/channelz/channelmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,6 @@ func copyMap(m map[int64]string) map[int64]string {
return n
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func (c *channelMap) getTopChannels(id int64, maxResults int) ([]*Channel, bool) {
if maxResults <= 0 {
maxResults = EntriesPerPage
Expand Down
7 changes: 0 additions & 7 deletions internal/transport/controlbuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,3 @@ func (l *loopyWriter) processData() (bool, error) {
}
return false, nil
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
9 changes: 1 addition & 8 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1684,13 +1684,6 @@ func (t *http2Client) reader(errCh chan<- error) {
}
}

func minTime(a, b time.Duration) time.Duration {
if a < b {
return a
}
return b
}

// keepalive running in a separate goroutine makes sure the connection is alive by sending pings.
func (t *http2Client) keepalive() {
p := &ping{data: [8]byte{}}
Expand Down Expand Up @@ -1758,7 +1751,7 @@ func (t *http2Client) keepalive() {
// timeoutLeft. This will ensure that we wait only for kp.Time
// before sending out the next ping (for cases where the ping is
// acked).
sleepDuration := minTime(t.kp.Time, timeoutLeft)
sleepDuration := min(t.kp.Time, timeoutLeft)
timeoutLeft -= sleepDuration
timer.Reset(sleepDuration)
case <-t.ctx.Done():
Expand Down
2 changes: 1 addition & 1 deletion internal/transport/http2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ func (t *http2Server) keepalive() {
// timeoutLeft. This will ensure that we wait only for kp.Time
// before sending out the next ping (for cases where the ping is
// acked).
sleepDuration := minTime(t.kp.Time, kpTimeoutLeft)
sleepDuration := min(t.kp.Time, kpTimeoutLeft)
kpTimeoutLeft -= sleepDuration
kpTimer.Reset(sleepDuration)
case <-t.done:
Expand Down
7 changes: 0 additions & 7 deletions test/end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4743,13 +4743,6 @@ type windowSizeConfig struct {
clientConn int32
}

func max(a, b int32) int32 {
if a > b {
return a
}
return b
}

func (s) TestConfigurableWindowSizeWithLargeWindow(t *testing.T) {
wc := windowSizeConfig{
serverStream: 8 * 1024 * 1024,
Expand Down
14 changes: 0 additions & 14 deletions xds/internal/balancer/outlierdetection/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,20 +592,6 @@ func (b *outlierDetectionBalancer) Target() string {
return b.cc.Target()
}

func max(x, y time.Duration) time.Duration {
if x < y {
return y
}
return x
}

func min(x, y time.Duration) time.Duration {
if x < y {
return x
}
return y
}

// handleSubConnUpdate stores the recent state and forward the update
// if the SubConn is not ejected.
func (b *outlierDetectionBalancer) handleSubConnUpdate(u *scUpdate) {
Expand Down

0 comments on commit 6a5a283

Please sign in to comment.