bytes, strings: use builtin min function in genSplit

Replace if n > len(s)+1 { n = len(s)+1 } pattern with the more
concise min(n, len(s)+1) built-in function.

This reduces 3 lines of code and improves readability.

Change-Id: I20a17139e98548ef0e01aa00b13b0fb5927bcfd1
Reviewed-on: https://go-review.googlesource.com/c/go/+/778740
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
cuishuang 2026-05-17 12:13:29 +08:00 committed by Gopher Robot
parent 03d1f8efc8
commit 64315a2d18
2 changed files with 2 additions and 6 deletions

View file

@ -380,9 +380,7 @@ func genSplit(s, sep []byte, sepSave, n int) [][]byte {
if n < 0 {
n = Count(s, sep) + 1
}
if n > len(s)+1 {
n = len(s) + 1
}
n = min(n, len(s)+1)
a := make([][]byte, n)
n--

View file

@ -282,9 +282,7 @@ func genSplit(s, sep string, sepSave, n int) []string {
n = Count(s, sep) + 1
}
if n > len(s)+1 {
n = len(s) + 1
}
n = min(n, len(s)+1)
a := make([]string, n)
n--
i := 0