enhancement: replace sort.Slice with slices.SortFunc to reduce reflection
This commit is contained in:
@@ -2,10 +2,10 @@ package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golang.org/x/exp/slices"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
||||
@@ -128,11 +128,9 @@ func (l *DiskLocation) loadAllEcShards() (err error) {
|
||||
}
|
||||
dirEntries = append(dirEntries, indexDirEntries...)
|
||||
}
|
||||
|
||||
sort.Slice(dirEntries, func(i, j int) bool {
|
||||
return dirEntries[i].Name() < dirEntries[j].Name()
|
||||
slices.SortFunc(dirEntries, func(a, b os.DirEntry) bool {
|
||||
return a.Name() < b.Name()
|
||||
})
|
||||
|
||||
var sameVolumeShards []string
|
||||
var prevVolumeId needle.VolumeId
|
||||
for _, fileInfo := range dirEntries {
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/volume_info"
|
||||
"golang.org/x/exp/slices"
|
||||
"math"
|
||||
"os"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -82,9 +82,8 @@ func (ev *EcVolume) AddEcVolumeShard(ecVolumeShard *EcVolumeShard) bool {
|
||||
}
|
||||
}
|
||||
ev.Shards = append(ev.Shards, ecVolumeShard)
|
||||
sort.Slice(ev.Shards, func(i, j int) bool {
|
||||
return ev.Shards[i].VolumeId < ev.Shards[j].VolumeId ||
|
||||
ev.Shards[i].VolumeId == ev.Shards[j].VolumeId && ev.Shards[i].ShardId < ev.Shards[j].ShardId
|
||||
slices.SortFunc(ev.Shards, func(a, b *EcVolumeShard) bool {
|
||||
return a.VolumeId < b.VolumeId || a.VolumeId == b.VolumeId && a.ShardId < b.ShardId
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||
"golang.org/x/exp/slices"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -389,8 +389,8 @@ func (s *Store) EcVolumes() (ecVolumes []*erasure_coding.EcVolume) {
|
||||
}
|
||||
location.ecVolumesLock.RUnlock()
|
||||
}
|
||||
sort.Slice(ecVolumes, func(i, j int) bool {
|
||||
return ecVolumes[i].VolumeId > ecVolumes[j].VolumeId
|
||||
slices.SortFunc(ecVolumes, func(a, b *erasure_coding.EcVolume) bool {
|
||||
return a.VolumeId > b.VolumeId
|
||||
})
|
||||
return ecVolumes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user