containerd/pkg/cri
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
..
annotations Added support for runtime level snapshotter, issue 6657 2022-06-02 16:29:59 -07:00
config reference CDI configuration details 2022-09-21 11:25:28 +03:00
constants move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
io Add logging volume metrics to Containerd CRI plugin 2022-10-19 10:47:49 -04:00
opts replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
sbserver replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
server replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
store remove unneeded nolint-comments (nolintlint), disable deprecated linters 2022-10-12 14:41:01 +02:00
streaming pkg/cri/streaming: increase ReadHeaderTimeout 2022-08-18 07:42:12 +08:00
util Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
cri.go Make getServicesOpts a helper 2022-07-22 19:38:45 -07:00