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/filer/stream.go | |
| 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/filer/stream.go')
| -rw-r--r-- | weed/filer/stream.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/weed/filer/stream.go b/weed/filer/stream.go index 36278f0b1..7da9fd0a0 100644 --- a/weed/filer/stream.go +++ b/weed/filer/stream.go @@ -3,6 +3,7 @@ package filer import ( "bytes" "fmt" + "golang.org/x/exp/slices" "io" "math" "sort" @@ -39,11 +40,11 @@ func isSameChunks(a, b []*filer_pb.FileChunk) bool { if len(a) != len(b) { return false } - sort.Slice(a, func(i, j int) bool { - return strings.Compare(a[i].ETag, a[j].ETag) < 0 + slices.SortFunc(a, func(i, j *filer_pb.FileChunk) bool { + return strings.Compare(i.ETag, j.ETag) < 0 }) - sort.Slice(b, func(i, j int) bool { - return strings.Compare(b[i].ETag, b[j].ETag) < 0 + slices.SortFunc(b, func(i, j *filer_pb.FileChunk) bool { + return strings.Compare(i.ETag, j.ETag) < 0 }) for i := 0; i < len(a); i++ { if a[i].ETag != b[i].ETag { @@ -179,8 +180,8 @@ var _ = io.ReaderAt(&ChunkStreamReader{}) func doNewChunkStreamReader(lookupFileIdFn wdclient.LookupFileIdFunctionType, chunks []*filer_pb.FileChunk) *ChunkStreamReader { chunkViews := ViewFromChunks(lookupFileIdFn, chunks, 0, math.MaxInt64) - sort.Slice(chunkViews, func(i, j int) bool { - return chunkViews[i].LogicOffset < chunkViews[j].LogicOffset + slices.SortFunc(chunkViews, func(a, b *ChunkView) bool { + return a.LogicOffset < b.LogicOffset }) var totalSize int64 |
