Skip to content

Commit b6d4f6b

Browse files
fjlkaralabe
authored andcommitted
core/types: remove BlockBy sorting code (#20355)
1 parent 0ec5ab4 commit b6d4f6b

2 files changed

Lines changed: 4 additions & 26 deletions

File tree

‎core/blockchain.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io"
2424
"math/big"
2525
mrand "math/rand"
26+
"sort"
2627
"sync"
2728
"sync/atomic"
2829
"time"
@@ -855,8 +856,9 @@ func (bc *BlockChain) procFutureBlocks() {
855856
}
856857
}
857858
if len(blocks) > 0 {
858-
types.BlockBy(types.Number).Sort(blocks)
859-
859+
sort.Slice(blocks, func(i, j int) bool {
860+
return blocks[i].NumberU64() < blocks[j].NumberU64()
861+
})
860862
// Insert one by one as chain insertion needs contiguous ancestry between blocks
861863
for i := range blocks {
862864
bc.InsertChain(blocks[i : i+1])

‎core/types/block.go‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"io"
2424
"math/big"
2525
"reflect"
26-
"sort"
2726
"sync/atomic"
2827
"time"
2928

@@ -394,26 +393,3 @@ func (b *Block) Hash() common.Hash {
394393
}
395394

396395
type Blocks []*Block
397-
398-
type BlockBy func(b1, b2 *Block) bool
399-
400-
func (self BlockBy) Sort(blocks Blocks) {
401-
bs := blockSorter{
402-
blocks: blocks,
403-
by: self,
404-
}
405-
sort.Sort(bs)
406-
}
407-
408-
type blockSorter struct {
409-
blocks Blocks
410-
by func(b1, b2 *Block) bool
411-
}
412-
413-
func (self blockSorter) Len() int { return len(self.blocks) }
414-
func (self blockSorter) Swap(i, j int) {
415-
self.blocks[i], self.blocks[j] = self.blocks[j], self.blocks[i]
416-
}
417-
func (self blockSorter) Less(i, j int) bool { return self.by(self.blocks[i], self.blocks[j]) }
418-
419-
func Number(b1, b2 *Block) bool { return b1.header.Number.Cmp(b2.header.Number) < 0 }

0 commit comments

Comments
 (0)