aboutsummaryrefslogtreecommitdiff
path: root/weed/util
diff options
context:
space:
mode:
authorjustin <leyou240@live.cn>2022-04-18 10:35:43 +0800
committerjustin <leyou240@live.cn>2022-04-18 10:35:43 +0800
commit3551ca2fcf423464afb2db4b5792c22ec94c2bfd (patch)
treeee1f372e32fb03d93aeb0825ec0f068ef1fce161 /weed/util
parentc6ec5269f4b34d79ab8e13050623501b8befda32 (diff)
downloadseaweedfs-3551ca2fcf423464afb2db4b5792c22ec94c2bfd.tar.xz
seaweedfs-3551ca2fcf423464afb2db4b5792c22ec94c2bfd.zip
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.go10
-rw-r--r--weed/util/skiplist/name_batch.go6
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) {