Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion misc/ios/go_ios_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func copyLocalData(dstbase string) (pkgpath string, err error) {
// Copy all immediate files and testdata directories between
// the package being tested and the source root.
pkgpath = ""
for _, element := range strings.Split(finalPkgpath, string(filepath.Separator)) {
for element := range strings.SplitSeq(finalPkgpath, string(filepath.Separator)) {
if debug {
log.Printf("copying %s", pkgpath)
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/cgo/gcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (f *File) loadDefines(gccOptions []string) bool {
stdout := gccDefines(b.Bytes(), gccOptions)

var gccIsClang bool
for _, line := range strings.Split(stdout, "\n") {
for line := range strings.SplitSeq(stdout, "\n") {
if len(line) < 9 || line[0:7] != "#define" {
continue
}
Expand Down Expand Up @@ -418,7 +418,7 @@ func (p *Package) guessKinds(f *File) []*Name {
notDeclared
)
sawUnmatchedErrors := false
for _, line := range strings.Split(stderr, "\n") {
for line := range strings.SplitSeq(stderr, "\n") {
// Ignore warnings and random comments, with one
// exception: newer GCC versions will sometimes emit
// an error on a macro #define with a note referring
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cgo/internal/test/testx.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func issue7978check(t *testing.T, wantFunc string, badFunc string, depth int) {
runtime.GC()
buf := make([]byte, 65536)
trace := string(buf[:runtime.Stack(buf, true)])
for _, goroutine := range strings.Split(trace, "\n\n") {
for goroutine := range strings.SplitSeq(trace, "\n\n") {
if strings.Contains(goroutine, "test.issue7978go") {
trace := strings.Split(goroutine, "\n")
// look for the expected function in the stack
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ func readEmbedCfg(file string) {

// parseSpectre parses the spectre configuration from the string s.
func parseSpectre(s string) {
for _, f := range strings.Split(s, ",") {
for f := range strings.SplitSeq(s, ",") {
f = strings.TrimSpace(f)
switch f {
default:
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func findgoversion() string {
if i := strings.Index(b, "\n"); i >= 0 {
rest := b[i+1:]
b = chomp(b[:i])
for _, line := range strings.Split(rest, "\n") {
for line := range strings.SplitSeq(rest, "\n") {
f := strings.Fields(line)
if len(f) == 0 {
continue
Expand Down Expand Up @@ -1137,7 +1137,7 @@ func shouldbuild(file, pkg string) bool {
}

// Check file contents for //go:build lines.
for _, p := range strings.Split(readfile(file), "\n") {
for p := range strings.SplitSeq(readfile(file), "\n") {
p = strings.TrimSpace(p)
if p == "" {
continue
Expand Down Expand Up @@ -2016,7 +2016,7 @@ func cmdlist() {
}

func setNoOpt() {
for _, gcflag := range strings.Split(gogcflags, " ") {
for gcflag := range strings.SplitSeq(gogcflags, " ") {
if gcflag == "-N" || gcflag == "-l" {
noOpt = true
break
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/distpack/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func readVERSION(goroot string) (version string, t time.Time) {
log.Fatal(err)
}
version, rest, _ := strings.Cut(string(data), "\n")
for _, line := range strings.Split(rest, "\n") {
for line := range strings.SplitSeq(rest, "\n") {
f := strings.Fields(line)
if len(f) == 0 {
continue
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/fix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func main() {

if *allowedRewrites != "" {
allowed = make(map[string]bool)
for _, f := range strings.Split(*allowedRewrites, ",") {
for f := range strings.SplitSeq(*allowedRewrites, ",") {
allowed[f] = true
}
}

if *forceRewrites != "" {
force = make(map[string]bool)
for _, f := range strings.Split(*forceRewrites, ",") {
for f := range strings.SplitSeq(*forceRewrites, ",") {
force[f] = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/auth/gitauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func runGitAuth(client *http.Client, dir, url string) (string, http.Header, erro
// Any of these values may be empty if parsing fails.
func parseGitAuth(data []byte) (parsedPrefix, username, password string) {
prefix := new(url.URL)
for _, line := range strings.Split(string(data), "\n") {
for line := range strings.SplitSeq(string(data), "\n") {
key, value, ok := strings.Cut(strings.TrimSpace(line), "=")
if !ok {
continue
Expand Down
75 changes: 75 additions & 0 deletions src/cmd/go/internal/auth/gitauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package auth

import (
"strings"
"testing"
)

Expand Down Expand Up @@ -82,3 +83,77 @@ password:secr3t
}
}
}

func BenchmarkParseGitAuth(b *testing.B) {
// Define different test scenarios to benchmark
testCases := []struct {
name string
data []byte
}{{
// Standard scenario with all basic fields present
name: "standard",
data: []byte(`
protocol=https
host=example.com
username=bob
password=secr3t
`),
}, {
// Scenario with URL field included
name: "with_url",
data: []byte(`
protocol=https
host=example.com
username=bob
password=secr3t
url=https://example.com/repo
`),
}, {
// Minimal scenario with only required fields
name: "minimal",
data: []byte(`
protocol=https
host=example.com
`),
}, {
// Complex scenario with longer values and extra fields
name: "complex",
data: func() []byte {
var builder strings.Builder
builder.WriteString("protocol=https\n")
builder.WriteString("host=example.com\n")
builder.WriteString("username=longusernamenamename\n")
builder.WriteString("password=longpasswordwithmanycharacters123456789\n")
builder.WriteString("url=https://example.com/very/long/path/to/repository\n")
builder.WriteString("extra1=value1\n")
builder.WriteString("extra2=value2\n")
return []byte(builder.String())
}(),
}, {
// Scenario with empty input
name: "empty",
data: []byte(``),
}, {
// Scenario with malformed input (using colon instead of equals)
name: "malformed",
data: []byte(`
protocol:https
host:example.com
username:bob
password:secr3t
`),
}}

for _, tc := range testCases {
b.Run(tc.name, func(b *testing.B) {
b.ResetTimer()
for b.Loop() {
prefix, username, password := parseGitAuth(tc.data)

_ = prefix
_ = username
_ = password
}
})
}
}
2 changes: 1 addition & 1 deletion src/cmd/go/internal/auth/netrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func parseNetrc(data string) []netrcLine {
var nrc []netrcLine
var l netrcLine
inMacro := false
for _, line := range strings.Split(data, "\n") {
for line := range strings.SplitSeq(data, "\n") {
if inMacro {
if line == "" {
inMacro = false
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/doc/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func findCodeRoots() []Dir {
cmd := exec.Command(goCmd(), "list", "-m", "-f={{.Path}}\t{{.Dir}}", "all")
cmd.Stderr = os.Stderr
out, _ := cmd.Output()
for _, line := range strings.Split(string(out), "\n") {
for line := range strings.SplitSeq(string(out), "\n") {
path, dir, _ := strings.Cut(line, "\t")
if dir != "" {
list = append(list, Dir{importPath: path, dir: dir, inModule: true})
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/doc/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ func trimUnexportedFields(fields *ast.FieldList, isInterface bool) *ast.FieldLis

start := doc.List[0].Slash
doc.List = doc.List[:0]
for _, line := range strings.Split(text, "\n") {
for line := range strings.SplitSeq(text, "\n") {
prefix := "// "
if len(line) > 0 && line[0] == '\t' {
prefix = "//"
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (v *jsonFlag) Set(s string) error {
if *v == nil {
*v = make(map[string]bool)
}
for _, f := range strings.Split(s, ",") {
for f := range strings.SplitSeq(s, ",") {
(*v)[f] = true
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/go/internal/modfetch/codehost/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *gitRepo) loadLocalTags(ctx context.Context) {
return
}

for _, line := range strings.Split(string(out), "\n") {
for line := range strings.SplitSeq(string(out), "\n") {
if line != "" {
r.localTags.Store(line, true)
}
Expand Down Expand Up @@ -273,7 +273,7 @@ func (r *gitRepo) loadRefs(ctx context.Context) (map[string]string, error) {
}

refs := make(map[string]string)
for _, line := range strings.Split(string(out), "\n") {
for line := range strings.SplitSeq(string(out), "\n") {
f := strings.Fields(line)
if len(f) != 2 {
continue
Expand Down Expand Up @@ -745,7 +745,7 @@ func (r *gitRepo) RecentTag(ctx context.Context, rev, prefix string, allowed fun

// prefixed tags aren't valid semver tags so compare without prefix, but only tags with correct prefix
var highest string
for _, line := range strings.Split(string(out), "\n") {
for line := range strings.SplitSeq(string(out), "\n") {
line = strings.TrimSpace(line)
// git do support lstrip in for-each-ref format, but it was added in v2.13.0. Stripping here
// instead gives support for git v2.7.0.
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/modfetch/codehost/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ func bzrParseStat(rev, out string) (*RevInfo, error) {
var revno int64
var tm time.Time
var tags []string
for _, line := range strings.Split(out, "\n") {
for line := range strings.SplitSeq(out, "\n") {
if line == "" || line[0] == ' ' || line[0] == '\t' {
// End of header, start of commit message.
break
Expand Down Expand Up @@ -614,7 +614,7 @@ func bzrParseStat(rev, out string) (*RevInfo, error) {
}

func fossilParseStat(rev, out string) (*RevInfo, error) {
for _, line := range strings.Split(out, "\n") {
for line := range strings.SplitSeq(out, "\n") {
if strings.HasPrefix(line, "uuid:") || strings.HasPrefix(line, "hash:") {
f := strings.Fields(line)
if len(f) != 5 || len(f[1]) != 40 || f[4] != "UTC" {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modindex/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ Lines:
// These lines set CFLAGS, CPPFLAGS, CXXFLAGS and LDFLAGS and pkg-config directives
// that affect the way cgo's C code is built.
func (ctxt *Context) saveCgo(filename string, di *build.Package, text string) error {
for _, line := range strings.Split(text, "\n") {
for line := range strings.SplitSeq(text, "\n") {
orig := line

// Line is
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modindex/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func importRaw(modroot, reldir string) *rawPackage {
// which is the comment on import "C".
func extractCgoDirectives(doc string) []string {
var out []string
for _, line := range strings.Split(doc, "\n") {
for line := range strings.SplitSeq(doc, "\n") {
// Line is
// #cgo [GOOS/GOARCH...] LDFLAGS: stuff
//
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modload/buildlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func readModGraph(ctx context.Context, pruning modPruning, roots []module.Versio
// so it wouldn't be useful to log when that occurs (because it happens in
// normal operation all the time).
readModGraphDebugOnce.Do(func() {
for _, f := range strings.Split(os.Getenv("GODEBUG"), ",") {
for f := range strings.SplitSeq(os.Getenv("GODEBUG"), ",") {
switch f {
case "lazymod=log":
debug.PrintStack()
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modload/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ func modulesTextIsForWorkspace(vendorDir string) (bool, error) {
}
line, _, _ := strings.Cut(string(buf[:n]), "\n")
if annotations, ok := strings.CutPrefix(line, "## "); ok {
for _, entry := range strings.Split(annotations, ";") {
for entry := range strings.SplitSeq(annotations, ";") {
entry = strings.TrimSpace(entry)
if entry == "workspace" {
return true, nil
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/modload/vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func readVendorList(vendorDir string) {
}

var mod module.Version
for _, line := range strings.Split(string(data), "\n") {
for line := range strings.SplitSeq(string(data), "\n") {
if strings.HasPrefix(line, "# ") {
f := strings.Fields(line)

Expand Down Expand Up @@ -103,7 +103,7 @@ func readVendorList(vendorDir string) {
if annotations, ok := strings.CutPrefix(line, "## "); ok {
// Metadata. Take the union of annotations across multiple lines, if present.
meta := vendorMeta[mod]
for _, entry := range strings.Split(annotations, ";") {
for entry := range strings.SplitSeq(annotations, ";") {
entry = strings.TrimSpace(entry)
if entry == "explicit" {
meta.Explicit = true
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/test/testflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (f *vetFlag) Set(value string) error {

*f = vetFlag{explicit: true}
var single string
for _, arg := range strings.Split(value, ",") {
for arg := range strings.SplitSeq(value, ",") {
switch arg {
case "":
return fmt.Errorf("-vet argument contains empty list element")
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/toolchain/path_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var pathExts = sync.OnceValue(func() []string {
}

var exts []string
for _, e := range strings.Split(strings.ToLower(x), `;`) {
for e := range strings.SplitSeq(strings.ToLower(x), `;`) {
if e == "" {
continue
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/go/internal/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (v *Cmd) isSecureScheme(scheme string) bool {
// colon-separated list of schemes that are allowed to be used with git
// fetch/clone. Any scheme not mentioned will be considered insecure.
if allow := os.Getenv("GIT_ALLOW_PROTOCOL"); allow != "" {
for _, s := range strings.Split(allow, ":") {
for s := range strings.SplitSeq(allow, ":") {
if s == scheme {
return true
}
Expand Down Expand Up @@ -440,7 +440,7 @@ func bzrStatus(vcsBzr *Cmd, rootDir string) (Status, error) {
var rev string
var commitTime time.Time

for _, line := range strings.Split(out, "\n") {
for line := range strings.SplitSeq(out, "\n") {
i := strings.IndexByte(line, ':')
if i < 0 {
continue
Expand Down Expand Up @@ -974,7 +974,7 @@ func parseGOVCS(s string) (govcsConfig, error) {
}
var cfg govcsConfig
have := make(map[string]string)
for _, item := range strings.Split(s, ",") {
for item := range strings.SplitSeq(s, ",") {
item = strings.TrimSpace(item)
if item == "" {
return nil, fmt.Errorf("empty entry in GOVCS")
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/vcweb/vcweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// uniqueness: if a path exists as a directory, then it cannot exist as a
// ".txt" script (because the search would ignore that file).
scriptPath := "."
for _, part := range strings.Split(clean, "/") {
for part := range strings.SplitSeq(clean, "/") {
scriptPath = filepath.Join(scriptPath, part)
dir := filepath.Join(s.scriptDir, scriptPath)
if _, err := os.Stat(dir); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/work/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (v *tagsFlag) Set(s string) error {

// Split on commas, ignore empty strings.
*v = []string{}
for _, s := range strings.Split(s, ",") {
for s := range strings.SplitSeq(s, ",") {
if s != "" {
*v = append(*v, s)
}
Expand Down
Loading