containerd/pkg
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
..
apparmor Run gofmt 1.19 2022-08-04 18:18:33 -07:00
atomic use containerd/project header test 2020-04-22 19:35:37 -05:00
cap replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
cri replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
dialer feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
epoch archive: add WithSourceDateEpoch() for whiteouts 2022-10-08 08:45:03 +09:00
failpoint Run gofmt 1.19 2022-08-04 18:18:33 -07:00
ioutil Run gofmt 1.19 2022-08-04 18:18:33 -07:00
kmutex CRI: improve image pulling performance 2022-04-06 07:14:18 +08:00
netns clean-up "nolint" comments, remove unused ones 2022-10-12 14:40:59 +02:00
oom Merge pull request #6323 from jepio/jepio/fix-cgroupv2-oom-event 2022-03-24 15:51:28 +08:00
os Run gofmt 1.19 2022-08-04 18:18:33 -07:00
process Consolidate gogo/protobuf dependencies under our own protobuf package 2022-04-19 15:53:36 +00:00
progress update golangci-lint to v1.49.0 2022-10-12 14:41:01 +02:00
registrar feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
runtimeoptions/v1 clean-up "nolint" comments, remove unused ones 2022-10-12 14:40:59 +02:00
schedcore add runc shim support for sched core 2021-10-08 16:18:09 +00:00
seccomp Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
seed Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
seutil seutil: Fix setting the "container_kvm_t" label 2021-12-14 00:09:17 +01:00
shutdown Split runc shim into plugin components 2021-11-15 20:16:45 -08:00
stdio Add logging binary support when terminal is true 2020-08-25 17:28:29 -07:00
testutil Use testify 2022-04-01 18:17:58 -07:00
timeout feat: use rwmutex instead 2021-11-16 11:06:40 +08:00
truncindex CRI: Move truncindex to pkg 2022-05-26 13:02:45 -07:00
ttrpcutil using ContextDialer instead 2022-07-20 22:53:42 +08:00
unpack add SpanAttribute 2022-11-03 18:34:06 +00:00
userns Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00