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.
@@ -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)
+ // 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 := cgPath
- if innerPath == "" {
innerPath = filepath.Join(cgParent, cgName)
}
