Skip to content

Commit 3fc2b90

Browse files
cuishuanggopherbot
authored andcommitted
all: use built-in max/min to simplify the code
Change-Id: I7d6cbc384698c810899b0c118096e1c6f99374fa Reviewed-on: https://go-review.googlesource.com/c/perf/+/664838 Reviewed-by: Michael Pratt <[email protected]> Auto-Submit: Sean Liao <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Sean Liao <[email protected]>
1 parent 71ba5bc commit 3fc2b90

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

cmd/benchstat/internal/texttab/table.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ func (t *Table) SetShrink(col int, shrink bool) {
125125
t.shrink[col] = shrink
126126
}
127127

128-
func max(a, b int) int {
129-
if a > b {
130-
return a
131-
}
132-
return b
133-
}
134-
135128
// Format lays out table t and writes it to w.
136129
func (t *Table) Format(w io.Writer) error {
137130
shrink := func(col int) bool {

internal/stats/alg.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@ import (
1010
"fmt"
1111
)
1212

13-
func maxint(a, b int) int {
14-
if a > b {
15-
return a
16-
}
17-
return b
18-
}
19-
20-
func minint(a, b int) int {
21-
if a < b {
22-
return a
23-
}
24-
return b
25-
}
26-
2713
func sumint(xs []int) int {
2814
sum := 0
2915
for _, x := range xs {

internal/stats/udist.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ func makeUmemo(twoU, n1 int, t []int) []map[ukey]float64 {
234234

235235
// Construct A[k] from A[k+1].
236236
for A_kplus1 := range A[k+1] {
237-
rkLow := maxint(0, A_kplus1.n1-tsum)
238-
rkHigh := minint(A_kplus1.n1, t[k])
237+
rkLow := max(0, A_kplus1.n1-tsum)
238+
rkHigh := min(A_kplus1.n1, t[k])
239239
for rk := rkLow; rk <= rkHigh; rk++ {
240240
twoU_k := A_kplus1.twoU - rk*(a[k+1]-2*A_kplus1.n1+rk)
241241
n1_k := A_kplus1.n1 - rk
@@ -261,7 +261,7 @@ func makeUmemo(twoU, n1 int, t []int) []map[ukey]float64 {
261261
N_2 := t[0] + t[1]
262262
for A_2i := range A[2] {
263263
Asum := 0.0
264-
r2Low := maxint(0, A_2i.n1-t[0])
264+
r2Low := max(0, A_2i.n1-t[0])
265265
r2High := (A_2i.twoU - A_2i.n1*(t[0]-A_2i.n1)) / N_2
266266
for r2 := r2Low; r2 <= r2High; r2++ {
267267
Asum += mathChoose(t[0], A_2i.n1-r2) *
@@ -278,8 +278,8 @@ func makeUmemo(twoU, n1 int, t []int) []map[ukey]float64 {
278278
// Compute A[k] counts from A[k-1] counts.
279279
for A_ki := range A[k] {
280280
Asum := 0.0
281-
rkLow := maxint(0, A_ki.n1-tsum)
282-
rkHigh := minint(A_ki.n1, t[k-1])
281+
rkLow := max(0, A_ki.n1-tsum)
282+
rkHigh := min(A_ki.n1, t[k-1])
283283
for rk := rkLow; rk <= rkHigh; rk++ {
284284
twoU_kminus1 := A_ki.twoU - rk*(a[k]-2*A_ki.n1+rk)
285285
n1_kminus1 := A_ki.n1 - rk
@@ -301,7 +301,7 @@ func twoUmin(n1 int, t, a []int) int {
301301
twoU := -n1 * n1
302302
n1_k := n1
303303
for k := 1; k <= K; k++ {
304-
twoU_k := minint(n1_k, t[k-1])
304+
twoU_k := min(n1_k, t[k-1])
305305
twoU += twoU_k * a[k]
306306
n1_k -= twoU_k
307307
}
@@ -313,7 +313,7 @@ func twoUmax(n1 int, t, a []int) int {
313313
twoU := -n1 * n1
314314
n1_k := n1
315315
for k := K; k > 0; k-- {
316-
twoU_k := minint(n1_k, t[k-1])
316+
twoU_k := min(n1_k, t[k-1])
317317
twoU += twoU_k * a[k]
318318
n1_k -= twoU_k
319319
}

0 commit comments

Comments
 (0)