From 5c7cb837c77ed98b74751fbcb6f1289e1dfd13e8 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 10 Aug 2021 13:06:31 -0700 Subject: [PATCH] libct/cg/fs: micro optimization In case c.Path is set, c.Name and c.Parent are not used, and so calls to utils.CleanPath are entirely unnecessary. Move them to inside of the "if" statement body. Get rid of the intermediate cgPath variable, it is not needed. Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs/paths.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libcontainer/cgroups/fs/paths.go b/libcontainer/cgroups/fs/paths.go index befa81bcb..671353ac8 100644 --- a/libcontainer/cgroups/fs/paths.go +++ b/libcontainer/cgroups/fs/paths.go @@ -122,13 +122,11 @@ func getCgroupData(c *configs.Cgroup, pid int) (*cgroupData, error) { return nil, errors.New("cgroup: either Path or Name and Parent should be used") } - // XXX: Do not remove this code. Path safety is important! -- cyphar - cgPath := utils.CleanPath(c.Path) - cgParent := utils.CleanPath(c.Parent) - cgName := utils.CleanPath(c.Name) - - innerPath := cgPath + // XXX: Do not remove CleanPath. Path safety is important! -- cyphar + innerPath := utils.CleanPath(c.Path) if innerPath == "" { + cgParent := utils.CleanPath(c.Parent) + cgName := utils.CleanPath(c.Name) innerPath = filepath.Join(cgParent, cgName) }