containerd/images
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
..
archive archive: validate digests before use 2022-10-06 19:37:31 -07:00
converter Fix missing close 2022-09-06 22:56:40 +08:00
annotations.go Use a single custom annotation for export 2019-05-21 17:21:26 -07:00
diffid.go image: use generic decompressor for calculating DiffID 2021-03-31 10:21:47 +09:00
handlers.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
image_test.go images: validate document type before unmarshal 2021-11-15 11:54:11 -08:00
image.go Merge pull request #6851 from whoreyou/images-typo-20220425 2022-04-25 11:44:49 -07:00
importexport.go Refactor image importer 2018-09-14 14:21:26 -07:00
mediatypes.go replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00