From 1ea5ad52e0bb50f5df2be38b75bcc197396de3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 2 May 2026 10:33:21 +0100 Subject: [PATCH] all: use strings.SplitSeq and strings.Cut to avoid intermediate slices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the remaining range-over-strings.Split sites with strings.SplitSeq, and replace strings.Split(s, sep)[0] with strings.Cut. Signed-off-by: Daniel Martí Change-Id: I0bdb2b0932dda019dfea2393103c72b0d3c60671 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1236529 Reviewed-by: Matthew Sackman Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo --- cue/inject/embed/embed.go | 4 +++- internal/core/adt/log.go | 2 +- internal/cuetxtar/inline_attr.go | 2 +- pkg/qgo.go | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cue/inject/embed/embed.go b/cue/inject/embed/embed.go index 587def0b1..748fd62eb 100644 --- a/cue/inject/embed/embed.go +++ b/cue/inject/embed/embed.go @@ -347,12 +347,14 @@ func fsGlob(fsys iofs.FS, pattern string) ([]string, error) { func filterFsGlobResults(pattern string, matches ...string) []string { patElems := strings.Split(pattern, "/") included := func(m string) bool { - for i, elem := range strings.Split(m, "/") { + i := 0 + for elem := range strings.SplitSeq(m, "/") { // Technically there should never be more elements in m than // there are in patElems, but be defensive and check bounds just in case. if strings.HasPrefix(elem, ".") && (i >= len(patElems) || !strings.HasPrefix(patElems[i], ".")) { return false } + i++ } return true } diff --git a/internal/core/adt/log.go b/internal/core/adt/log.go index 2852d7b69..dfdddf0ee 100644 --- a/internal/core/adt/log.go +++ b/internal/core/adt/log.go @@ -73,7 +73,7 @@ func (c *OpContext) Indentf(v *Vertex, format string, args ...any) (s nestString // any arguments passed to ...args above escape to the heap and allocate. panic("avoid calling OpContext.Indentf when logging is disabled to prevent overhead") } - name := strings.Split(format, "(")[0] + name, _, _ := strings.Cut(format, "(") if name == "" { name, _ = getCallerFunctionName(1) format = name + format diff --git a/internal/cuetxtar/inline_attr.go b/internal/cuetxtar/inline_attr.go index 9bd5213a2..39f69e288 100644 --- a/internal/cuetxtar/inline_attr.go +++ b/internal/cuetxtar/inline_attr.go @@ -516,7 +516,7 @@ func parseAtPath(at string) (cue.Path, error) { return p, p.Err() } var sels []cue.Selector - for _, seg := range strings.Split(at, ".") { + for seg := range strings.SplitSeq(at, ".") { if internal.IsHidden(seg) { name := seg pkg := "_" diff --git a/pkg/qgo.go b/pkg/qgo.go index 6544f1882..804d1379f 100644 --- a/pkg/qgo.go +++ b/pkg/qgo.go @@ -101,7 +101,7 @@ func main() { var exclusions []*regexp.Regexp func initExclusions() { - for _, re := range strings.Split(*exclude, ",") { + for re := range strings.SplitSeq(*exclude, ",") { if re != "" { exclusions = append(exclusions, regexp.MustCompile(re)) } -- 2.51.2