From 5d04aae8969f6c72318ce0a4cde4f027766b1a55 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 17 Jan 2025 10:28:16 +0100 Subject: all: use min/max functions They are shorter, more readable, and don't require temp vars. --- pkg/bisect/bisect.go | 16 ++-------------- pkg/bisect/minimize/slice.go | 5 +---- 2 files changed, 3 insertions(+), 18 deletions(-) (limited to 'pkg/bisect') 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 -- cgit mrf-deployment