modernize: Prefer strings.SplitSeq instead of Split

Avoids extra allocations. Added in Go 1.24.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-12-15 17:53:59 +01:00
parent c9b0a21bb1
commit a25907b485
29 changed files with 50 additions and 50 deletions

View File

@@ -861,7 +861,7 @@ type buildLine struct {
func getImageIDsFromBuild(output []byte) ([]string, error) {
var ids []string
for _, line := range bytes.Split(output, []byte("\n")) {
for line := range bytes.SplitSeq(output, []byte("\n")) {
if len(line) == 0 {
continue
}

View File

@@ -891,7 +891,7 @@ func TestFirewallBackendSwitch(t *testing.T) {
})
// TODO: (When Go 1.24 is min version) Replace with `strings.Lines(dump)`.
for _, line := range strings.Split(dump, "\n") {
for line := range strings.SplitSeq(dump, "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue

View File

@@ -1591,7 +1591,7 @@ func checkProxies(ctx context.Context, t *testing.T, c *client.Client, daemonPid
t.Error(res)
return
}
for _, line := range strings.Split(res.Stdout(), "\n") {
for line := range strings.SplitSeq(res.Stdout(), "\n") {
_, args, ok := strings.Cut(line, "docker-proxy")
if !ok {
continue
@@ -1785,7 +1785,7 @@ func TestAdvertiseAddresses(t *testing.T) {
// the associated MAC address.
findNeighMAC := func(neighOut, ip string) string {
t.Helper()
for _, line := range strings.Split(neighOut, "\n") {
for line := range strings.SplitSeq(neighOut, "\n") {
// Lines look like ...
// 172.22.22.22 dev eth0 lladdr 36:bc:ce:67:f3:e4 ref 1 used 0/7/0 probes 1 DELAY
fields := strings.Fields(line)
@@ -2015,7 +2015,7 @@ func TestLegacyLinksEnvVars(t *testing.T) {
// Check the list of environment variables set in the linking container.
var found bool
for _, l := range strings.Split(exportRes.Stdout.String(), "\n") {
for l := range strings.SplitSeq(exportRes.Stdout.String(), "\n") {
if strings.HasPrefix(l, "export CTR1_") {
// Legacy links env var found, but not expected.
if !tc.expectEnvVars {

View File

@@ -281,8 +281,8 @@ func enableIPv6OnAll(t *testing.T) func() {
ifaces := map[string]string{}
var allVal string
sysctls := strings.Split(string(out), "\n")
for _, sysctl := range sysctls {
sysctls := strings.SplitSeq(string(out), "\n")
for sysctl := range sysctls {
if sysctl == "" {
continue
}