containerd/services
Sebastiaan van Stijn eaedadbed0
replace strings.Split(N) for strings.Cut() or alternatives
Go 1.18 and up now provides a strings.Cut() which is better suited for
splitting key/value pairs (and similar constructs), and performs better:

```go
func BenchmarkSplit(b *testing.B) {
        b.ReportAllocs()
        data := []string{"12hello=world", "12hello=", "12=hello", "12hello"}
        for i := 0; i < b.N; i++ {
                for _, s := range data {
                        _ = strings.SplitN(s, "=", 2)[0]
                }
        }
}

func BenchmarkCut(b *testing.B) {
        b.ReportAllocs()
        data := []string{"12hello=world", "12hello=", "12=hello", "12hello"}
        for i := 0; i < b.N; i++ {
                for _, s := range data {
                        _, _, _ = strings.Cut(s, "=")
                }
        }
}
```

    BenchmarkSplit
    BenchmarkSplit-10            8244206               128.0 ns/op           128 B/op          4 allocs/op
    BenchmarkCut
    BenchmarkCut-10             54411998                21.80 ns/op            0 B/op          0 allocs/op

While looking at occurrences of `strings.Split()`, I also updated some for alternatives,
or added some constraints; for cases where an specific number of items is expected, I used `strings.SplitN()`
with a suitable limit. This prevents (theoretical) unlimited splits.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-07 10:02:25 +01:00
..
containers Embed "Unimplemented" structs as proto recommended 2022-04-20 17:14:23 +00:00
content Rename Size_ to Size 2022-04-22 15:31:53 +00:00
diff archive: add WithSourceDateEpoch() for whiteouts 2022-10-08 08:45:03 +09:00
events Embed "Unimplemented" structs as proto recommended 2022-04-20 17:14:23 +00:00
healthcheck Licence header added 2018-02-19 10:32:26 +09:00
images Rename Size_ to Size 2022-04-22 15:31:53 +00:00
introspection fix some confusing typos 2022-05-17 23:53:36 +08:00
leases Embed "Unimplemented" structs as proto recommended 2022-04-20 17:14:23 +00:00
namespaces Embed "Unimplemented" structs as proto recommended 2022-04-20 17:14:23 +00:00
opt feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
sandbox Cleanup sandbox interfaces 2022-10-25 12:31:32 -04:00
server replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
snapshots Add snapshotter key to snapshot events 2022-06-20 18:25:53 -07:00
tasks Make TaskList generic 2022-08-10 14:02:53 -07:00
version Embed "Unimplemented" structs as proto recommended 2022-04-20 17:14:23 +00:00
services.go Merge pull request #6703 from mxpv/s 2022-04-18 20:55:06 -07:00