Replace `for _, s := range {strings, bytes}.Split(v, sep)` with
`for s := range {strings, bytes}.SplitSeq(v, sep)`, to simplify
the code and reduce some memory allocations.
Change-Id: Idead4de1e3928fc75cc5ba8caeff85542f1243d5
GitHub-Last-Rev:
5fb196a073e7583b23b1ebb446d6c067580ed63a
GitHub-Pull-Request: golang/go#71554
Reviewed-on: https://go-review.googlesource.com/c/go/+/646216
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
}
var ranges []httpRange
noOverlap := false
- for _, ra := range strings.Split(s[len(b):], ",") {
+ for ra := range strings.SplitSeq(s[len(b):], ",") {
ra = textproto.TrimString(ra)
if ra == "" {
continue
if trailers, ok := rw.snapHeader["Trailer"]; ok {
res.Trailer = make(http.Header, len(trailers))
for _, k := range trailers {
- for _, k := range strings.Split(k, ",") {
+ for k := range strings.SplitSeq(k, ",") {
k = http.CanonicalHeaderKey(textproto.TrimString(k))
if !httpguts.ValidTrailerHeader(k) {
// Ignore since forbidden by RFC 7230, section 4.1.2.
func removeHopByHopHeaders(h http.Header) {
// RFC 7230, section 6.1: Remove headers listed in the "Connection" header.
for _, f := range h["Connection"] {
- for _, sf := range strings.Split(f, ",") {
+ for sf := range strings.SplitSeq(f, ",") {
if sf = textproto.TrimString(sf); sf != "" {
h.Del(sf)
}
c := r.Header["Connection"]
var cf []string
for _, f := range c {
- for _, sf := range strings.Split(f, ",") {
+ for sf := range strings.SplitSeq(f, ",") {
if sf = strings.TrimSpace(sf); sf != "" {
cf = append(cf, sf)
}
func interestingGoroutines() (gs []string) {
buf := make([]byte, 2<<20)
buf = buf[:runtime.Stack(buf, true)]
- for _, g := range strings.Split(string(buf), "\n\n") {
+ for g := range strings.SplitSeq(string(buf), "\n\n") {
_, stack, _ := strings.Cut(g, "\n")
stack = strings.TrimSpace(stack)
if stack == "" ||
fn(v)
return
}
- for _, f := range strings.Split(v, ",") {
+ for f := range strings.SplitSeq(v, ",") {
if f = textproto.TrimString(f); f != "" {
fn(f)
}
var gss []string
b := make([]byte, 2<<20)
b = b[:runtime.Stack(b, true)]
- for _, s := range strings.Split(string(b), "\n\n") {
+ for s := range strings.SplitSeq(string(b), "\n\n") {
_, stack, _ := strings.Cut(s, "\n")
stack = strings.TrimSpace(stack)
if !strings.Contains(stack, "created by net") {
//Metric : 10
//...
var name string
- lines := bytes.Split(out, []byte{'\r', '\n'})
- for _, line := range lines {
+ for line := range bytes.SplitSeq(out, []byte{'\r', '\n'}) {
if bytes.HasPrefix(line, []byte("Interface ")) && bytes.HasSuffix(line, []byte(" Parameters")) {
f := line[len("Interface "):]
f = f[:len(f)-len(" Parameters")]
addrs := make([]string, 0)
var addr, subnetprefix string
var processingOurInterface bool
- lines := bytes.Split(netshOutput, []byte{'\r', '\n'})
- for _, line := range lines {
+ for line := range bytes.SplitSeq(netshOutput, []byte{'\r', '\n'}) {
if !processingOurInterface {
if !bytes.HasPrefix(line, []byte("Configuration for interface")) {
continue
// TODO: need to test ipv6 netmask too, but netsh does not outputs it
var addr string
addrs := make([]string, 0)
- lines := bytes.Split(netshOutput, []byte{'\r', '\n'})
- for _, line := range lines {
+ for line := range bytes.SplitSeq(netshOutput, []byte{'\r', '\n'}) {
if addr != "" {
if len(line) == 0 {
addr = ""
want[cname] = addr
group = make(map[string]string)
}
- lines := bytes.Split(out, []byte{'\r', '\n'})
- for _, line := range lines {
+ for line := range bytes.SplitSeq(out, []byte{'\r', '\n'}) {
if len(line) == 0 {
processGroup()
continue