Skip to content

Commit 40ce69c

Browse files
committed
libct/cg/fs2: use strings.Cut in setUnified
Using strings.Cut (added in Go 1.18, see [1]) results in faster and cleaner code with less allocations (as we're not using a slice). The code is tested by testCgroupResourcesUnified. [1]: golang/go#46336 Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 037668e commit 40ce69c

File tree

1 file changed

+2
-3
lines changed
  • libcontainer/cgroups/fs2

1 file changed

+2
-3
lines changed

libcontainer/cgroups/fs2/fs2.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,10 @@ func (m *Manager) setUnified(res map[string]string) error {
237237
if errors.Is(err, os.ErrPermission) || errors.Is(err, os.ErrNotExist) {
238238
// Check if a controller is available,
239239
// to give more specific error if not.
240-
sk := strings.SplitN(k, ".", 2)
241-
if len(sk) != 2 {
240+
c, _, ok := strings.Cut(k, ".")
241+
if !ok {
242242
return fmt.Errorf("unified resource %q must be in the form CONTROLLER.PARAMETER", k)
243243
}
244-
c := sk[0]
245244
if _, ok := m.controllers[c]; !ok && c != "cgroup" {
246245
return fmt.Errorf("unified resource %q can't be set: controller %q not available", k, c)
247246
}

0 commit comments

Comments
 (0)