Skip to content

Commit 454d339

Browse files
authored
refactor: use strings.SplitSeq for streaming iteration (#516)
Replaces `strings.Split` with `strings.SplitSeq` in to iterate over split results without allocating an intermediate slice. This reduces memory allocations and enables streaming-style processing. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
1 parent f119b5c commit 454d339

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

builder/vmware/common/driver_parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ func decodeDhcpdLeaseBytes(input string) ([]byte, error) {
22702270
processed := &bytes.Buffer{}
22712271

22722272
// Split the string into pieces as we'll need to validate it.
2273-
for _, item := range strings.Split(input, ":") {
2273+
for item := range strings.SplitSeq(input, ":") {
22742274
if len(item) != 2 {
22752275
return []byte{}, fmt.Errorf("bytes are not well-formed (%v)", input)
22762276
}

builder/vmware/common/vmx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ParseVMX(contents string) map[string]string {
2121

2222
lineRe := regexp.MustCompile(`^(.+?)\s*=\s*"?(.*?)"?\s*$`)
2323

24-
for _, line := range strings.Split(contents, "\n") {
24+
for line := range strings.SplitSeq(contents, "\n") {
2525
matches := lineRe.FindStringSubmatch(line)
2626
if matches == nil {
2727
continue

0 commit comments

Comments
 (0)