From 614acbb748f022f892937619f70cb62ed8357a3e Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 27 Mar 2023 17:47:32 -0700 Subject: [PATCH] libct/cg/sd/v2: unifiedResToSystemdProps nit In code that checks that the resource name is in the for Using strings.SplitN is an overkill in this case, resulting in allocations and thus garbage to collect. Using strings.IndexByte and checking that result is not less than 1 (meaning there is a period, and it is not the first character) is sufficient here. Fixes: 0cb8bf67a3418996820ae Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/systemd/v2.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libcontainer/cgroups/systemd/v2.go b/libcontainer/cgroups/systemd/v2.go index 3d66ed40610..0301bf10076 100644 --- a/libcontainer/cgroups/systemd/v2.go +++ b/libcontainer/cgroups/systemd/v2.go @@ -64,8 +64,7 @@ func unifiedResToSystemdProps(cm *dbusConnManager, res map[string]string) (props if strings.Contains(k, "/") { return nil, fmt.Errorf("unified resource %q must be a file name (no slashes)", k) } - sk := strings.SplitN(k, ".", 2) - if len(sk) != 2 { + if strings.IndexByte(k, '.') < 2 { return nil, fmt.Errorf("unified resource %q must be in the form CONTROLLER.PARAMETER", k) } // Kernel is quite forgiving to extra whitespace