containerd/cmd/ctr/commands
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 ctr: Fix ctr c create fails to parse arguments 2022-06-23 21:52:53 +09:00
content ctr: add ctr content fetch-blob 2022-11-04 11:41:11 +09:00
events ctr events: do not exit on an error 2020-01-29 13:10:16 +09:00
images ctr export strictly match default platform 2022-11-01 17:35:30 +00:00
install Add optional install path 2018-09-11 10:36:00 -04:00
leases replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
namespaces feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
oci feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
plugins Remove all gogoproto extensions 2022-04-20 07:23:28 +00:00
pprof Fix missing closed HTTP Body 2022-06-28 14:49:27 +08:00
run replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
sandboxes ctr sandbox: handle sandbox config 2022-05-19 15:28:49 +03:00
shim Move runtime v2 proto 2022-04-19 17:59:33 -07:00
snapshots archive: add WithSourceDateEpoch() for whiteouts 2022-10-08 08:45:03 +09:00
tasks fix the --no-pivot flag being ignored by ctr tasks start 2022-10-13 11:50:26 +08:00
version adding go version to client description 2019-10-06 13:38:51 +02:00
client.go implement ctr -connect-timeout 2019-09-16 13:56:53 +02:00
cni.go Run gofmt 1.19 2022-08-04 18:18:33 -07:00
commands_unix.go Implement --device idType://id for ctr run on Windows 2022-03-12 08:16:43 +11:00
commands_windows.go Add ctr support for CPUMax and CPUShares 2022-04-28 13:17:16 -07:00
commands.go replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
resolver.go Fix ctr crash when pulling with http-trace and http-dump 2022-11-01 16:28:39 -07:00
signals_linux.go Ignore SIGURG signals in signal forwarder 2020-09-04 16:19:31 -07:00
signals_notlinux.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
signals.go Ignore SIGURG signals in signal forwarder 2020-09-04 16:19:31 -07:00
utils.go Implemented image encryption/decryption libraries and ctr commands 2019-07-17 15:19:58 -04:00