Skip to content

Commit 92bc667

Browse files
committed
sysinfo: use bits.OnesCount64, drop popcnt
Slightly less code to maintain. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 9254b3b commit 92bc667

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

Diff for: pkg/sysinfo/numcpu_windows.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package sysinfo
44

55
import (
6+
"math/bits"
67
"unsafe"
78

89
"golang.org/x/sys/windows"
@@ -22,7 +23,5 @@ func numCPU() int {
2223
if ret == 0 {
2324
return 0
2425
}
25-
// For every available thread a bit is set in the mask.
26-
ncpu := int(popcnt(uint64(mask)))
27-
return ncpu
26+
return bits.OnesCount64(uint64(mask))
2827
}

Diff for: pkg/sysinfo/sysinfo.go

-10
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,6 @@ func isCpusetListAvailable(provided, available string) (bool, error) {
133133
return true, nil
134134
}
135135

136-
// Returns bit count of 1, used by NumCPU
137-
func popcnt(x uint64) (n byte) {
138-
x -= (x >> 1) & 0x5555555555555555
139-
x = (x>>2)&0x3333333333333333 + x&0x3333333333333333
140-
x += x >> 4
141-
x &= 0x0f0f0f0f0f0f0f0f
142-
x *= 0x0101010101010101
143-
return byte(x >> 56)
144-
}
145-
146136
// GetDefaultPidsLimit returns the default pids limit to run containers with
147137
func GetDefaultPidsLimit() int64 {
148138
sysInfo := New(true)

0 commit comments

Comments
 (0)