Merge pull request #77421 from tedyu/cpu-free-no-sort

Obtain unsorted slice in cpuAccumulator#freeCores
k3s-v1.15.3
Kubernetes Prow Robot 2019-05-16 16:26:53 -07:00 committed by GitHub
commit b276043051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

@ -188,6 +188,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.
//