getProcPids() minor improvement

reduce allocs a little bit.
This commit is contained in:
Gustavo Iñiguez Goia 2024-10-09 23:54:40 +02:00
parent 83fad69316
commit 3bf429b9ca
Failed to generate hash of commit

View file

@ -84,18 +84,19 @@ func lookupPidDescriptors(fdPath string, pid int) []string {
} }
// getProcPids returns the list of running PIDs, /proc or /proc/<pid>/task/ . // getProcPids returns the list of running PIDs, /proc or /proc/<pid>/task/ .
func getProcPids(pidsPath string) (pidList []int) { func getProcPids(pidsPath string) []int {
f, err := os.Open(pidsPath) f, err := os.Open(pidsPath)
if err != nil { if err != nil {
return pidList return []int{}
} }
ls, err := f.Readdir(-1) ls, err := f.Readdir(-1)
f.Close() f.Close()
if err != nil { if err != nil {
return pidList return []int{}
} }
ls = sortPidsByTime(ls) ls = sortPidsByTime(ls)
pidList := make([]int, 0, len(ls))
for _, f := range ls { for _, f := range ls {
if f.IsDir() == false { if f.IsDir() == false {
continue continue