17
17
package blobpool
18
18
19
19
import (
20
- "bytes"
21
20
"container/heap"
22
21
"math"
23
- "sort "
22
+ "slices "
24
23
25
24
"github.com/ethereum/go-ethereum/common"
26
25
"github.com/holiman/uint256"
26
+ "golang.org/x/exp/maps"
27
27
)
28
28
29
29
// evictHeap is a helper data structure to keep track of the cheapest bottleneck
@@ -49,20 +49,15 @@ type evictHeap struct {
49
49
func newPriceHeap (basefee * uint256.Int , blobfee * uint256.Int , index map [common.Address ][]* blobTxMeta ) * evictHeap {
50
50
heap := & evictHeap {
51
51
metas : index ,
52
- index : make (map [common.Address ]int ),
52
+ index : make (map [common.Address ]int , len ( index ) ),
53
53
}
54
54
// Populate the heap in account sort order. Not really needed in practice,
55
55
// but it makes the heap initialization deterministic and less annoying to
56
56
// test in unit tests.
57
- addrs := make ([]common.Address , 0 , len (index ))
58
- for addr := range index {
59
- addrs = append (addrs , addr )
60
- }
61
- sort .Slice (addrs , func (i , j int ) bool { return bytes .Compare (addrs [i ][:], addrs [j ][:]) < 0 })
62
-
63
- for _ , addr := range addrs {
64
- heap .index [addr ] = len (heap .addrs )
65
- heap .addrs = append (heap .addrs , addr )
57
+ heap .addrs = maps .Keys (index )
58
+ slices .SortFunc (heap .addrs , common .Address .Cmp )
59
+ for i , addr := range heap .addrs {
60
+ heap .index [addr ] = i
66
61
}
67
62
heap .reinit (basefee , blobfee , true )
68
63
return heap
0 commit comments