]> Cypherpunks repositories - gostls13.git/commitdiff
all: use built-in min, max functions
authorMarcel Meyer <mm.marcelmeyer@gmail.com>
Fri, 11 Apr 2025 22:19:49 +0000 (22:19 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 11 Apr 2025 23:00:30 +0000 (16:00 -0700)
Change-Id: Ie76ebb556d635068342747f3f91dd7dc423df531
GitHub-Last-Rev: aea61fb3a054e6bd24f4684f90fb353d5682cd0b
GitHub-Pull-Request: golang/go#73340
Reviewed-on: https://go-review.googlesource.com/c/go/+/664677
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
src/internal/poll/copy_file_range_unix.go
src/os/root_unix.go
src/runtime/debug/garbage_test.go
src/time/sleep_test.go

index d3d3aaeed1391010e90d285b0d317f28681ec19d..d39c5a339d5895ca1480a74fbe39e435810449d1 100644 (file)
@@ -16,10 +16,7 @@ func CopyFileRange(dst, src *FD, remain int64) (written int64, handled bool, err
        }
 
        for remain > 0 {
-               max := remain
-               if max > maxCopyFileRangeRound {
-                       max = maxCopyFileRangeRound
-               }
+               max := min(remain, maxCopyFileRangeRound)
                n, e := copyFileRange(dst, src, int(max))
                if n > 0 {
                        remain -= n
index 19a84c4da0857c66f98842e5a426e50e4898f717..74320451d5b536432dd2b7312d70c3421d31198f 100644 (file)
@@ -272,9 +272,7 @@ func readlinkat(fd int, name string) (string, error) {
                if e != nil {
                        return "", e
                }
-               if n < 0 {
-                       n = 0
-               }
+               n = max(n, 0)
                if n < len {
                        return string(b[0:n]), nil
                }
index cd91782d27c1cedddbbbfbd87e0efc53ce41ac1d..506f698ad72a8e9a9dd5df115dce675c74db9f45 100644 (file)
@@ -18,7 +18,7 @@ func TestReadGCStats(t *testing.T) {
 
        var stats GCStats
        var mstats runtime.MemStats
-       var min, max time.Duration
+       var minimum, maximum time.Duration
 
        // First ReadGCStats will allocate, second should not,
        // especially if we follow up with an explicit garbage collection.
@@ -52,11 +52,11 @@ func TestReadGCStats(t *testing.T) {
                        if dt != time.Duration(mstats.PauseNs[off]) {
                                t.Errorf("stats.Pause[%d] = %d, want %d", i, dt, mstats.PauseNs[off])
                        }
-                       if max < dt {
-                               max = dt
-                       }
-                       if min > dt || i == 0 {
-                               min = dt
+                       maximum = max(maximum, dt)
+                       if i == 0 {
+                               minimum = dt
+                       } else {
+                               minimum = min(minimum, dt)
                        }
                        off = (off + len(mstats.PauseNs) - 1) % len(mstats.PauseNs)
                }
@@ -64,8 +64,8 @@ func TestReadGCStats(t *testing.T) {
 
        q := stats.PauseQuantiles
        nq := len(q)
-       if q[0] != min || q[nq-1] != max {
-               t.Errorf("stats.PauseQuantiles = [%d, ..., %d], want [%d, ..., %d]", q[0], q[nq-1], min, max)
+       if q[0] != minimum || q[nq-1] != maximum {
+               t.Errorf("stats.PauseQuantiles = [%d, ..., %d], want [%d, ..., %d]", q[0], q[nq-1], minimum, maximum)
        }
 
        for i := 0; i < nq-1; i++ {
index 285a2e748c4af7cb3dd6948e3c9858755e9c6c59..b9e81b98febef27231a9065140e6fe68ff7f7885 100644 (file)
@@ -968,17 +968,15 @@ func BenchmarkParallelTimerLatency(b *testing.B) {
        }
        var total float64
        var samples float64
-       max := Duration(0)
+       maximum := Duration(0)
        for _, s := range stats {
-               if s.max > max {
-                       max = s.max
-               }
+               maximum = max(maximum, s.max)
                total += s.sum
                samples += float64(s.count)
        }
        b.ReportMetric(0, "ns/op")
        b.ReportMetric(total/samples, "avg-late-ns")
-       b.ReportMetric(float64(max.Nanoseconds()), "max-late-ns")
+       b.ReportMetric(float64(maximum.Nanoseconds()), "max-late-ns")
 }
 
 // Benchmark timer latency with staggered wakeup times and varying CPU bound