Skip to content

Commit 03640f6

Browse files
mrclmrgopherbot
authored andcommitted
all: use built-in min, max functions
Change-Id: Ie76ebb556d635068342747f3f91dd7dc423df531 GitHub-Last-Rev: aea61fb GitHub-Pull-Request: #73340 Reviewed-on: https://go-review.googlesource.com/c/go/+/664677 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 56fad21 commit 03640f6

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

src/internal/poll/copy_file_range_unix.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ func CopyFileRange(dst, src *FD, remain int64) (written int64, handled bool, err
1616
}
1717

1818
for remain > 0 {
19-
max := remain
20-
if max > maxCopyFileRangeRound {
21-
max = maxCopyFileRangeRound
22-
}
19+
max := min(remain, maxCopyFileRangeRound)
2320
n, e := copyFileRange(dst, src, int(max))
2421
if n > 0 {
2522
remain -= n

src/os/root_unix.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ func readlinkat(fd int, name string) (string, error) {
272272
if e != nil {
273273
return "", e
274274
}
275-
if n < 0 {
276-
n = 0
277-
}
275+
n = max(n, 0)
278276
if n < len {
279277
return string(b[0:n]), nil
280278
}

src/runtime/debug/garbage_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestReadGCStats(t *testing.T) {
1818

1919
var stats GCStats
2020
var mstats runtime.MemStats
21-
var min, max time.Duration
21+
var minimum, maximum time.Duration
2222

2323
// First ReadGCStats will allocate, second should not,
2424
// especially if we follow up with an explicit garbage collection.
@@ -52,20 +52,20 @@ func TestReadGCStats(t *testing.T) {
5252
if dt != time.Duration(mstats.PauseNs[off]) {
5353
t.Errorf("stats.Pause[%d] = %d, want %d", i, dt, mstats.PauseNs[off])
5454
}
55-
if max < dt {
56-
max = dt
57-
}
58-
if min > dt || i == 0 {
59-
min = dt
55+
maximum = max(maximum, dt)
56+
if i == 0 {
57+
minimum = dt
58+
} else {
59+
minimum = min(minimum, dt)
6060
}
6161
off = (off + len(mstats.PauseNs) - 1) % len(mstats.PauseNs)
6262
}
6363
}
6464

6565
q := stats.PauseQuantiles
6666
nq := len(q)
67-
if q[0] != min || q[nq-1] != max {
68-
t.Errorf("stats.PauseQuantiles = [%d, ..., %d], want [%d, ..., %d]", q[0], q[nq-1], min, max)
67+
if q[0] != minimum || q[nq-1] != maximum {
68+
t.Errorf("stats.PauseQuantiles = [%d, ..., %d], want [%d, ..., %d]", q[0], q[nq-1], minimum, maximum)
6969
}
7070

7171
for i := 0; i < nq-1; i++ {

src/time/sleep_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -968,17 +968,15 @@ func BenchmarkParallelTimerLatency(b *testing.B) {
968968
}
969969
var total float64
970970
var samples float64
971-
max := Duration(0)
971+
maximum := Duration(0)
972972
for _, s := range stats {
973-
if s.max > max {
974-
max = s.max
975-
}
973+
maximum = max(maximum, s.max)
976974
total += s.sum
977975
samples += float64(s.count)
978976
}
979977
b.ReportMetric(0, "ns/op")
980978
b.ReportMetric(total/samples, "avg-late-ns")
981-
b.ReportMetric(float64(max.Nanoseconds()), "max-late-ns")
979+
b.ReportMetric(float64(maximum.Nanoseconds()), "max-late-ns")
982980
}
983981

984982
// Benchmark timer latency with staggered wakeup times and varying CPU bound

0 commit comments

Comments
 (0)