Skip to content

Commit 7c0b21b

Browse files
refactor: replace sort.Slice with slices.Sort for natural ordering (#635)
Signed-off-by: yingshanghuangqiao <[email protected]>
1 parent 1e5e2d9 commit 7c0b21b

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

pkg/consensus/consensus.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package consensus
88
import (
99
"errors"
1010
"fmt"
11-
"sort"
11+
"slices"
1212
"strings"
1313
"sync"
1414
"sync/atomic"
@@ -378,9 +378,7 @@ func (c *Consensus) setNodes(nodes []uint64) {
378378
func sortNodes(nodes []uint64) []uint64 {
379379
sorted := make([]uint64, len(nodes))
380380
copy(sorted, nodes)
381-
sort.Slice(sorted, func(i, j int) bool {
382-
return sorted[i] < sorted[j]
383-
})
381+
slices.Sort(sorted)
384382
return sorted
385383
}
386384

pkg/wal/util.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io"
1212
"os"
1313
"path/filepath"
14+
"slices"
1415
"sort"
1516
"strings"
1617

@@ -132,11 +133,7 @@ func checkWalFiles(logger api.Logger, dirName string, walNames []string) ([]uint
132133
}
133134
}
134135

135-
sort.Slice(indexes,
136-
func(i, j int) bool {
137-
return indexes[i] < indexes[j]
138-
},
139-
)
136+
slices.Sort(indexes)
140137

141138
return indexes, nil
142139
}

test/network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package test
88
import (
99
"fmt"
1010
"math/rand"
11-
"sort"
11+
"slices"
1212
"sync"
1313

1414
"github.com/hyperledger-labs/SmartBFT/smartbftprotos"
@@ -213,7 +213,7 @@ func (node *Node) SendTransaction(targetID uint64, request []byte) {
213213
// Nodes returns the ids of all nodes in the network
214214
func (node *Node) Nodes() []uint64 {
215215
res := node.n.getAll()
216-
sort.Slice(res, func(i, j int) bool { return res[i] < res[j] })
216+
slices.Sort(res)
217217
return res
218218
}
219219

0 commit comments

Comments
 (0)