mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
core, eth, accounts, trie: use slices.Concat
This commit is contained in:
parent
bce420b99f
commit
4397c712ac
6 changed files with 17 additions and 12 deletions
|
|
@ -18,6 +18,7 @@ package accounts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -255,7 +256,7 @@ func merge(slice []Wallet, wallets ...Wallet) []Wallet {
|
||||||
slice = append(slice, wallet)
|
slice = append(slice, wallet)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
slice = append(slice[:n], append([]Wallet{wallet}, slice[n:]...)...)
|
slice = slices.Concat(slice[:n], []Wallet{wallet}, slice[n:])
|
||||||
}
|
}
|
||||||
return slice
|
return slice
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"math"
|
"math"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
@ -417,7 +418,7 @@ func (m *Matcher) distributor(dist chan *request, session *MatcherSession) {
|
||||||
// New retrieval request arrived to be distributed to some fetcher process
|
// New retrieval request arrived to be distributed to some fetcher process
|
||||||
queue := requests[req.bit]
|
queue := requests[req.bit]
|
||||||
index := sort.Search(len(queue), func(i int) bool { return queue[i] >= req.section })
|
index := sort.Search(len(queue), func(i int) bool { return queue[i] >= req.section })
|
||||||
requests[req.bit] = append(queue[:index], append([]uint64{req.section}, queue[index:]...)...)
|
requests[req.bit] = slices.Concat(queue[:index], []uint64{req.section}, queue[index:])
|
||||||
|
|
||||||
// If it's a new bit and we have waiting fetchers, allocate to them
|
// If it's a new bit and we have waiting fetchers, allocate to them
|
||||||
if len(queue) == 0 {
|
if len(queue) == 0 {
|
||||||
|
|
@ -485,7 +486,7 @@ func (m *Matcher) distributor(dist chan *request, session *MatcherSession) {
|
||||||
queue := requests[result.Bit]
|
queue := requests[result.Bit]
|
||||||
for _, section := range missing {
|
for _, section := range missing {
|
||||||
index := sort.Search(len(queue), func(i int) bool { return queue[i] >= section })
|
index := sort.Search(len(queue), func(i int) bool { return queue[i] >= section })
|
||||||
queue = append(queue[:index], append([]uint64{section}, queue[index:]...)...)
|
queue = slices.Concat(queue[:index], []uint64{section}, queue[index:])
|
||||||
}
|
}
|
||||||
requests[result.Bit] = queue
|
requests[result.Bit] = queue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func newFilter(config *params.ChainConfig, genesis *types.Block, headfn func() (
|
||||||
// Calculate the all the valid fork hash and fork next combos
|
// Calculate the all the valid fork hash and fork next combos
|
||||||
var (
|
var (
|
||||||
forksByBlock, forksByTime = gatherForks(config, genesis.Time())
|
forksByBlock, forksByTime = gatherForks(config, genesis.Time())
|
||||||
forks = append(append([]uint64{}, forksByBlock...), forksByTime...)
|
forks = slices.Concat(forksByBlock, forksByTime)
|
||||||
sums = make([][4]byte, len(forks)+1) // 0th is the genesis
|
sums = make([][4]byte, len(forks)+1) // 0th is the genesis
|
||||||
)
|
)
|
||||||
hash := crc32.ChecksumIEEE(genesis.Hash().Bytes())
|
hash := crc32.ChecksumIEEE(genesis.Hash().Bytes())
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ package rawdb
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
|
@ -171,7 +172,7 @@ func headerKeyPrefix(number uint64) []byte {
|
||||||
|
|
||||||
// headerKey = headerPrefix + num (uint64 big endian) + hash
|
// headerKey = headerPrefix + num (uint64 big endian) + hash
|
||||||
func headerKey(number uint64, hash common.Hash) []byte {
|
func headerKey(number uint64, hash common.Hash) []byte {
|
||||||
return append(append(headerPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
|
return slices.Concat(headerPrefix, encodeBlockNumber(number), hash.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// headerTDKey = headerPrefix + num (uint64 big endian) + hash + headerTDSuffix
|
// headerTDKey = headerPrefix + num (uint64 big endian) + hash + headerTDSuffix
|
||||||
|
|
@ -181,7 +182,7 @@ func headerTDKey(number uint64, hash common.Hash) []byte {
|
||||||
|
|
||||||
// headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix
|
// headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix
|
||||||
func headerHashKey(number uint64) []byte {
|
func headerHashKey(number uint64) []byte {
|
||||||
return append(append(headerPrefix, encodeBlockNumber(number)...), headerHashSuffix...)
|
return slices.Concat(headerPrefix, encodeBlockNumber(number), headerHashSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// headerNumberKey = headerNumberPrefix + hash
|
// headerNumberKey = headerNumberPrefix + hash
|
||||||
|
|
@ -191,12 +192,12 @@ func headerNumberKey(hash common.Hash) []byte {
|
||||||
|
|
||||||
// blockBodyKey = blockBodyPrefix + num (uint64 big endian) + hash
|
// blockBodyKey = blockBodyPrefix + num (uint64 big endian) + hash
|
||||||
func blockBodyKey(number uint64, hash common.Hash) []byte {
|
func blockBodyKey(number uint64, hash common.Hash) []byte {
|
||||||
return append(append(blockBodyPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
|
return slices.Concat(blockBodyPrefix, encodeBlockNumber(number), hash.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// blockReceiptsKey = blockReceiptsPrefix + num (uint64 big endian) + hash
|
// blockReceiptsKey = blockReceiptsPrefix + num (uint64 big endian) + hash
|
||||||
func blockReceiptsKey(number uint64, hash common.Hash) []byte {
|
func blockReceiptsKey(number uint64, hash common.Hash) []byte {
|
||||||
return append(append(blockReceiptsPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
|
return slices.Concat(blockReceiptsPrefix, encodeBlockNumber(number), hash.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// txLookupKey = txLookupPrefix + hash
|
// txLookupKey = txLookupPrefix + hash
|
||||||
|
|
@ -225,7 +226,7 @@ func storageSnapshotsKey(accountHash common.Hash) []byte {
|
||||||
|
|
||||||
// bloomBitsKey = bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash
|
// bloomBitsKey = bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash
|
||||||
func bloomBitsKey(bit uint, section uint64, hash common.Hash) []byte {
|
func bloomBitsKey(bit uint, section uint64, hash common.Hash) []byte {
|
||||||
key := append(append(bloomBitsPrefix, make([]byte, 10)...), hash.Bytes()...)
|
key := slices.Concat(bloomBitsPrefix, make([]byte, 10), hash.Bytes())
|
||||||
|
|
||||||
binary.BigEndian.PutUint16(key[1:], uint16(bit))
|
binary.BigEndian.PutUint16(key[1:], uint16(bit))
|
||||||
binary.BigEndian.PutUint64(key[3:], section)
|
binary.BigEndian.PutUint64(key[3:], section)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -872,7 +873,7 @@ func (d *Downloader) processSnapSyncContent() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // results already piled up, consume before handling pivot move
|
} else { // results already piled up, consume before handling pivot move
|
||||||
results = append(append([]*fetchResult{oldPivot}, oldTail...), results...)
|
results = slices.Concat([]*fetchResult{oldPivot}, oldTail, results)
|
||||||
}
|
}
|
||||||
// Split around the pivot block and process the two sides via snap/full sync
|
// Split around the pivot block and process the two sides via snap/full sync
|
||||||
if !d.committed.Load() {
|
if !d.committed.Load() {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package trie
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -553,7 +554,7 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
|
||||||
}
|
}
|
||||||
children = []childNode{{
|
children = []childNode{{
|
||||||
node: node.Val,
|
node: node.Val,
|
||||||
path: append(append([]byte(nil), req.path...), key...),
|
path: slices.Concat(req.path, key),
|
||||||
}}
|
}}
|
||||||
// Mark all internal nodes between shortNode and its **in disk**
|
// Mark all internal nodes between shortNode and its **in disk**
|
||||||
// child as invalid. This is essential in the case of path mode
|
// child as invalid. This is essential in the case of path mode
|
||||||
|
|
@ -595,7 +596,7 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
|
||||||
if node.Children[i] != nil {
|
if node.Children[i] != nil {
|
||||||
children = append(children, childNode{
|
children = append(children, childNode{
|
||||||
node: node.Children[i],
|
node: node.Children[i],
|
||||||
path: append(append([]byte(nil), req.path...), byte(i)),
|
path: slices.Concat(req.path, []byte{i}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue