containerd/pkg/cri/server
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
..
bandwidth Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
testing update go-cni/for cni update fixing plugins that don't respond with version 2022-06-01 17:20:18 -05:00
blockio_linux.go cri: support blockio class in pod and container annotations 2022-04-29 11:44:09 +03:00
blockio_stub_linux.go cri: support blockio class in pod and container annotations 2022-04-29 11:44:09 +03:00
cni_conf_syncer.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
container_attach.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
container_checkpoint.go Set grpc code for unimplemented cri-api methods 2022-09-22 07:24:48 +00:00
container_create_linux_test.go improve CDI logging 2022-10-12 13:45:20 +03:00
container_create_linux.go CDI: configure registry on start 2022-10-12 13:45:20 +03:00
container_create_other_test.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
container_create_other.go Windows snapshotter touch ups and new functionality 2022-06-06 14:57:07 -07:00
container_create_test.go cri/server: Disable tests on FreeBSD 2022-06-09 18:54:10 -07:00
container_create_windows_test.go Add validations for Windows HostProcess CRI configs 2022-05-27 21:17:07 -07:00
container_create_windows.go maintenance: Remove WithWindowsNetworkNamespace from pkg/cri 2022-10-23 06:45:32 -07:00
container_create.go ContainerStatus to return container resources 2022-08-24 19:08:06 +00:00
container_events.go Set grpc code for unimplemented cri-api methods 2022-09-22 07:24:48 +00:00
container_exec.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
container_execsync_test.go Implicitly discard the input to drain the reader 2022-06-06 09:57:13 -07:00
container_execsync.go Implicitly discard the input to drain the reader 2022-06-06 09:57:13 -07:00
container_list_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
container_list.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
container_log_reopen.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
container_remove_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
container_remove.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
container_start_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
container_start.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
container_stats_list_linux_test.go Refactor usageNanoCores be to used for all OSes 2022-07-19 16:49:08 -07:00
container_stats_list_linux.go Refactor usageNanoCores be to used for all OSes 2022-07-19 16:49:08 -07:00
container_stats_list_other.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
container_stats_list_test.go Refactor usageNanoCores be to used for all OSes 2022-07-19 16:49:08 -07:00
container_stats_list_windows.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
container_stats_list.go remove unneeded nolint-comments (nolintlint), disable deprecated linters 2022-10-12 14:41:01 +02:00
container_stats.go remove unneeded nolint-comments (nolintlint), disable deprecated linters 2022-10-12 14:41:01 +02:00
container_status_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
container_status.go ContainerStatus to return container resources 2022-08-24 19:08:06 +00:00
container_stop_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
container_stop.go Remove gogoproto.stdtime 2022-04-19 13:39:30 +00:00
container_update_resources_linux_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
container_update_resources_linux.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
container_update_resources_other.go Update container with sandbox metadata after NetNS is created 2022-10-09 01:14:08 +00:00
container_update_resources_windows.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
container_update_resources.go ContainerStatus to return container resources 2022-08-24 19:08:06 +00:00
events_test.go Fix tests 2022-04-22 15:41:05 +00:00
events.go Run gofmt 1.19 2022-08-04 18:18:33 -07:00
fuzz.go Refactor CRI fuzzers 2022-09-19 22:14:11 +00:00
helpers_linux_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
helpers_linux.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
helpers_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
helpers_selinux_linux_test.go move up to CRI v1 and support v1alpha in parallel 2021-06-28 09:34:12 -05:00
helpers_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
helpers_windows.go Remove redundant build tags 2021-08-05 22:27:46 -07:00
helpers.go Add tracing spans in CRI image service and pull.go 2022-11-03 17:03:43 +00:00
image_list_test.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
image_list.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
image_pull_test.go Merge pull request #6899 from shuaichang/ISSUE6657-support-runtime-snapshotter 2022-06-03 10:04:53 +02:00
image_pull.go replace strings.Split(N) for strings.Cut() or alternatives 2022-11-07 10:02:25 +01:00
image_remove.go add SpanAttribute 2022-11-03 18:34:06 +00:00
image_status_test.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
image_status.go add SpanAttribute 2022-11-03 18:34:06 +00:00
imagefs_info_test.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
imagefs_info.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
instrumented_service.go Add tracing spans in CRI image service and pull.go 2022-11-03 17:03:43 +00:00
metrics.go [cri] add sandbox and container latency metrics 2021-11-09 21:07:38 +00:00
opts.go Move cri server packages under pkg/cri 2020-10-07 13:09:37 -07:00
rdt_linux.go cri: fix handling of ignore_rdt_not_enabled_errors config option 2022-02-04 13:54:03 +02:00
rdt_stub_linux.go Fix rdt build tags for go 1.16 2022-01-19 11:09:29 -08:00
restart.go fix some confusing typos 2022-05-17 23:53:36 +08:00
sandbox_list_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
sandbox_list.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
sandbox_portforward_linux.go chore: remove duplicate word in comments 2022-08-29 13:05:32 +08:00
sandbox_portforward_other.go chore: remove duplicate word in comments 2022-08-29 13:05:32 +08:00
sandbox_portforward_windows.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
sandbox_portforward.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
sandbox_remove.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
sandbox_run_linux_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
sandbox_run_linux.go Persist container and sandbox if resource cleanup fails, like teardownPodNetwork 2022-09-27 14:38:41 +00:00
sandbox_run_other_test.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
sandbox_run_other.go Persist container and sandbox if resource cleanup fails, like teardownPodNetwork 2022-09-27 14:38:41 +00:00
sandbox_run_test.go cri/server: Disable tests on FreeBSD 2022-06-09 18:54:10 -07:00
sandbox_run_windows_test.go Add RunAsUserName functionality for the Windows Pod Sandbox Container 2021-08-23 07:35:22 -07:00
sandbox_run_windows.go maintenance: Remove WithWindowsNetworkNamespace from pkg/cri 2022-10-23 06:45:32 -07:00
sandbox_run.go Update container with sandbox metadata after NetNS is created 2022-10-09 01:14:08 +00:00
sandbox_stats_linux.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
sandbox_stats_list.go remove unneeded nolint-comments (nolintlint), disable deprecated linters 2022-10-12 14:41:01 +02:00
sandbox_stats_other.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
sandbox_stats_windows.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
sandbox_stats.go remove unneeded nolint-comments (nolintlint), disable deprecated linters 2022-10-12 14:41:01 +02:00
sandbox_status_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
sandbox_status.go cri: PodSandboxStatus should tolerate missing task 2022-10-14 14:40:13 -07:00
sandbox_stop_test.go Use t.Run for /pkg/cri tests 2022-05-29 18:32:09 -07:00
sandbox_stop.go Remove gogoproto.stdtime 2022-04-19 13:39:30 +00:00
service_linux.go CDI: configure registry on start 2022-10-12 13:45:20 +03:00
service_other.go Run go fmt with Go 1.17 2021-08-22 09:31:50 +09:00
service_test.go Copy FuzzCRI from cncf/cncf-fuzzing 2022-06-27 22:54:25 +00:00
service_windows.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
service.go remove unneeded nolint-comments (nolintlint), disable deprecated linters 2022-10-12 14:41:01 +02:00
snapshots.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
status.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
streaming_test.go Move cri server packages under pkg/cri 2020-10-07 13:09:37 -07:00
streaming.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
test_config.go Copy FuzzCRI from cncf/cncf-fuzzing 2022-06-27 22:54:25 +00:00
update_runtime_config_test.go test: use T.TempDir to create temporary test directory 2022-03-15 14:03:50 +08:00
update_runtime_config.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00
version.go Replace golang.org/x/net/context with std library 2022-02-22 02:27:05 +08:00