4 ms·
Seems to have missed the strings.Cut* family added to go 1.18
by RenThraysk 3y ago
Seems to have missed the strings.Cut* family added to go 1.18
- costco 3y agoWell, they are implemented in a pretty similar way: https://cs.opensource.google/go/go/+/refs/tags/go1.21.4:src/strings/strings.go;l=1278 https://cs.opensource.google/go/go/+/refs/tags/go1.21.4:src/... so it shouldn't affect the benchmarks too much.
- tedunangst 3y agoCut only scans the string once (not twice) and doesn't allocate a slice to return.
- costco 3y agoMaybe I'm confused on how strings work but if this doesn't allocate: // excerpted from Cut if i := Index(s, sep); i >= 0 { return s[:i], s[i+len(sep):], true } return s, "", false Then why shouldn't this also not allocate? eoc = strings.Index(round, ", ") if eoc == -1 { currentScoreWithColor = round } else { currentScoreWithColor = round[:eoc] round = round[eoc+2:] } Edit: oh, you're comparing it to Split. I was comparing it to what they ended up implementing.