Skip to content

Commit 292521f

Browse files
committed
core: use slices package for sorting ethereum#27489 ethereum#27909
1 parent e6b1fe9 commit 292521f

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

core/mkalloc.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"fmt"
3131
"math/big"
3232
"os"
33-
"sort"
33+
"slices"
3434
"strconv"
3535

3636
"github.com/XinFinOrg/XDPoSChain/core"
@@ -39,23 +39,19 @@ import (
3939

4040
type allocItem struct{ Addr, Balance *big.Int }
4141

42-
type allocList []allocItem
43-
44-
func (a allocList) Len() int { return len(a) }
45-
func (a allocList) Less(i, j int) bool { return a[i].Addr.Cmp(a[j].Addr) < 0 }
46-
func (a allocList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
47-
48-
func makelist(g *core.Genesis) allocList {
49-
a := make(allocList, 0, len(g.Alloc))
42+
func makelist(g *core.Genesis) []allocItem {
43+
items := make([]allocItem, 0, len(g.Alloc))
5044
for addr, account := range g.Alloc {
5145
if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 {
5246
panic(fmt.Sprintf("can't encode account %x", addr))
5347
}
5448
bigAddr := new(big.Int).SetBytes(addr.Bytes())
55-
a = append(a, allocItem{bigAddr, account.Balance})
49+
items = append(items, allocItem{bigAddr, account.Balance})
5650
}
57-
sort.Sort(a)
58-
return a
51+
slices.SortFunc(items, func(a, b allocItem) int {
52+
return a.Addr.Cmp(b.Addr)
53+
})
54+
return items
5955
}
6056

6157
func makealloc(g *core.Genesis) string {

core/rawdb/accessors_chain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ func WriteBadBlock(db ethdb.KeyValueStore, block *types.Block) {
676676
Body: block.Body(),
677677
})
678678
slices.SortFunc(badBlocks, func(a, b *badBlock) int {
679-
// Note: sorting in descending number order.
680-
return -a.Header.Number.Cmp(b.Header.Number)
679+
// NOTE: sorting in descending number order.
680+
return b.Header.Number.Cmp(a.Header.Number)
681681
})
682682
if len(badBlocks) > badBlockToKeep {
683683
badBlocks = badBlocks[:badBlockToKeep]

0 commit comments

Comments
 (0)