mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-18 20:29:22 +08:00
enhancement: replace sort.Slice with slices.SortFunc to reduce reflection
This commit is contained in:
@@ -4,12 +4,11 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
"io"
|
||||
"sort"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
"golang.org/x/exp/slices"
|
||||
"io"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -411,8 +410,8 @@ func doBalanceEcRack(commandEnv *CommandEnv, ecRack *EcRack, applyBalancing bool
|
||||
hasMove := true
|
||||
for hasMove {
|
||||
hasMove = false
|
||||
sort.Slice(rackEcNodes, func(i, j int) bool {
|
||||
return rackEcNodes[i].freeEcSlot > rackEcNodes[j].freeEcSlot
|
||||
slices.SortFunc(rackEcNodes, func(a, b *EcNode) bool {
|
||||
return a.freeEcSlot > b.freeEcSlot
|
||||
})
|
||||
emptyNode, fullNode := rackEcNodes[0], rackEcNodes[len(rackEcNodes)-1]
|
||||
emptyNodeShardCount, fullNodeShardCount := ecNodeIdToShardCount[emptyNode.info.Id], ecNodeIdToShardCount[fullNode.info.Id]
|
||||
@@ -492,8 +491,8 @@ func pickNEcShardsToMoveFrom(ecNodes []*EcNode, vid needle.VolumeId, n int) map[
|
||||
})
|
||||
}
|
||||
}
|
||||
sort.Slice(candidateEcNodes, func(i, j int) bool {
|
||||
return candidateEcNodes[i].shardCount > candidateEcNodes[j].shardCount
|
||||
slices.SortFunc(candidateEcNodes, func(a, b *CandidateEcNode) bool {
|
||||
return a.shardCount > b.shardCount
|
||||
})
|
||||
for i := 0; i < n; i++ {
|
||||
selectedEcNodeIndex := -1
|
||||
|
Reference in New Issue
Block a user