Obtain unsorted slice in cpuAccumulator#freeCores

This commit is contained in:
Ted Yu 2019-05-03 14:07:44 -07:00 committed by Ted Yu
parent 16085784bc
commit f83bac61a4
2 changed files with 11 additions and 1 deletions

View File

@ -69,7 +69,7 @@ func (a *cpuAccumulator) freeSockets() []int {
// - socket ID, ascending
// - core ID, ascending
func (a *cpuAccumulator) freeCores() []int {
socketIDs := a.details.Sockets().ToSlice()
socketIDs := a.details.Sockets().ToSliceNoSort()
sort.Slice(socketIDs,
func(i, j int) bool {
iCores := a.details.CoresInSocket(socketIDs[i]).Filter(a.isCoreFree)

View File

@ -172,6 +172,16 @@ func (s CPUSet) ToSlice() []int {
return result
}
// ToSliceNoSort returns a slice of integers that contains all elements from
// this set.
func (s CPUSet) ToSliceNoSort() []int {
result := []int{}
for cpu := range s.elems {
result = append(result, cpu)
}
return result
}
// String returns a new string representation of the elements in this CPU set
// in canonical linux CPU list format.
//