aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/bisect
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2025-01-17 10:28:16 +0100
committerDmitry Vyukov <dvyukov@google.com>2025-01-17 10:02:07 +0000
commit5d04aae8969f6c72318ce0a4cde4f027766b1a55 (patch)
tree8f1b632847c431407090f0fe1335522ff2195a37 /pkg/bisect
parentf9e07a6e597b68d3397864e6ee4550f9065c3518 (diff)
all: use min/max functions
They are shorter, more readable, and don't require temp vars.
Diffstat (limited to 'pkg/bisect')
-rw-r--r--pkg/bisect/bisect.go16
-rw-r--r--pkg/bisect/minimize/slice.go5
2 files changed, 3 insertions, 18 deletions
diff --git a/pkg/bisect/bisect.go b/pkg/bisect/bisect.go
index 73a1971c8..ba022e514 100644
--- a/pkg/bisect/bisect.go
+++ b/pkg/bisect/bisect.go
@@ -928,9 +928,7 @@ func (env *env) postTestResult(res *testResult) {
// Let's be conservative and only decrease our reproduction likelihood estimate.
// As the estimate of each test() can also be flaky, only partially update the result.
avg := (env.reproChance + res.badRatio) / 2.0
- if env.reproChance > avg {
- env.reproChance = avg
- }
+ env.reproChance = min(env.reproChance, avg)
}
}
@@ -1086,7 +1084,7 @@ func pickReleaseTags(all []string) []string {
}
var ret []string
// Take 2 latest sub releases.
- takeSubReleases := minInts(2, len(subReleases))
+ takeSubReleases := min(2, len(subReleases))
ret = append(ret, subReleases[:takeSubReleases]...)
// If there are a lot of sub releases, also take the middle one.
if len(subReleases) > 5 {
@@ -1107,13 +1105,3 @@ func pickReleaseTags(all []string) []string {
}
return ret
}
-
-func minInts(vals ...int) int {
- ret := vals[0]
- for i := 1; i < len(vals); i++ {
- if vals[i] < ret {
- ret = vals[i]
- }
- }
- return ret
-}
diff --git a/pkg/bisect/minimize/slice.go b/pkg/bisect/minimize/slice.go
index fee125542..d5fbc6c6a 100644
--- a/pkg/bisect/minimize/slice.go
+++ b/pkg/bisect/minimize/slice.go
@@ -257,10 +257,7 @@ func splitChunk[T any](chunk []T, parts int) [][]T {
}
var ret [][]T
for i := 0; i < len(chunk); i += chunkSize {
- end := i + chunkSize
- if end > len(chunk) {
- end = len(chunk)
- }
+ end := min(i+chunkSize, len(chunk))
ret = append(ret, chunk[i:end])
}
return ret