containerd/metadata
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
..
boltutil Consolidate gogo/protobuf dependencies under our own protobuf package 2022-04-19 15:53:36 +00:00
plugin Move metadata plugin registration to seperate package 2022-06-22 17:38:41 -07:00
adaptors.go [sandbox] Implement metadata store 2022-04-08 13:33:47 -07:00
bolt.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
buckets.go Run gofmt 1.19 2022-08-04 18:18:33 -07:00
compare_test.go Fix tests 2022-04-22 15:41:05 +00:00
containers_test.go Make checkContainerTimestamps less strict on Windows 2022-08-31 17:37:57 +00:00
containers.go Consolidate gogo/protobuf dependencies under our own protobuf package 2022-04-19 15:53:36 +00:00
content_test.go Cleanup metadata tests 2022-06-27 14:42:22 -07:00
content.go Add shared content label to namespaces 2022-03-11 23:37:02 -08:00
db_test.go Cleanup metadata tests 2022-06-27 14:42:22 -07:00
db.go Run gofmt 1.19 2022-08-04 18:18:33 -07:00
gc_test.go Cleanup metadata tests 2022-06-27 14:42:22 -07:00
gc.go replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
images_test.go Cleanup metadata tests 2022-06-27 14:42:22 -07:00
images.go Revert "Add shared content label to namespaces" 2022-01-12 16:38:06 -08:00
leases_test.go Cleanup metadata tests 2022-06-27 14:42:22 -07:00
leases.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
migrations.go Adds a no-op migration for metadata v3 2018-09-12 15:33:42 -07:00
namespaces_test.go Cleanup metadata tests 2022-06-27 14:42:22 -07:00
namespaces.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
sandbox_test.go Cleanup metadata tests 2022-06-27 14:42:22 -07:00
sandbox.go Add sandbox store helpers 2022-07-28 14:17:39 -07:00
snapshot_test.go Cleanup metadata tests 2022-06-27 14:42:22 -07:00
snapshot.go docs: add doc-comments on GC-related methods 2022-01-24 14:26:14 -08:00