diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2022-04-17 20:59:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-17 20:59:31 -0700 |
| commit | 61af76c3bb03bf40e3444c50724c8d5a1a2eafb4 (patch) | |
| tree | e7bbc83368c814afa3d6c81c808738f91e32afd4 /weed/util | |
| parent | b597baf488fa4449d41ac2b78d421751f65f909e (diff) | |
| parent | 89eb87c1d16640030927af242b34eba47a149427 (diff) | |
| download | seaweedfs-61af76c3bb03bf40e3444c50724c8d5a1a2eafb4.tar.xz seaweedfs-61af76c3bb03bf40e3444c50724c8d5a1a2eafb4.zip | |
Merge pull request #2929 from leyou240/slices.SortFunc
enhancement: replace sort.Slice with slices.SortFunc to reduce reflection
Diffstat (limited to 'weed/util')
| -rw-r--r-- | weed/util/chunk_cache/on_disk_cache_layer.go | 10 | ||||
| -rw-r--r-- | weed/util/skiplist/name_batch.go | 6 |
2 files changed, 7 insertions, 9 deletions
diff --git a/weed/util/chunk_cache/on_disk_cache_layer.go b/weed/util/chunk_cache/on_disk_cache_layer.go index 9115b1bb1..de32fb445 100644 --- a/weed/util/chunk_cache/on_disk_cache_layer.go +++ b/weed/util/chunk_cache/on_disk_cache_layer.go @@ -2,12 +2,11 @@ package chunk_cache import ( "fmt" - "path" - "sort" - "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/storage" "github.com/chrislusf/seaweedfs/weed/storage/types" + "golang.org/x/exp/slices" + "path" ) type OnDiskCacheLayer struct { @@ -33,10 +32,9 @@ func NewOnDiskCacheLayer(dir, namePrefix string, diskSize int64, segmentCount in } // keep newest cache to the front - sort.Slice(c.diskCaches, func(i, j int) bool { - return c.diskCaches[i].lastModTime.After(c.diskCaches[j].lastModTime) + slices.SortFunc(c.diskCaches, func(a, b *ChunkCacheVolume) bool { + return a.lastModTime.After(b.lastModTime) }) - return c } diff --git a/weed/util/skiplist/name_batch.go b/weed/util/skiplist/name_batch.go index 71e5aeeba..53db5918f 100644 --- a/weed/util/skiplist/name_batch.go +++ b/weed/util/skiplist/name_batch.go @@ -3,7 +3,7 @@ package skiplist import ( "github.com/chrislusf/seaweedfs/weed/glog" "github.com/golang/protobuf/proto" - "sort" + "golang.org/x/exp/slices" "strings" ) @@ -41,8 +41,8 @@ func (nb *NameBatch) ListNames(startFrom string, visitNamesFn func(name string) names = append(names, n) } } - sort.Slice(names, func(i, j int) bool { - return strings.Compare(names[i], names[j]) < 0 + slices.SortFunc(names, func(a, b string) bool { + return strings.Compare(a, b) < 0 }) for _, n := range names { if !visitNamesFn(n) { |
