chore: reduce allocations

This commit is contained in:
Khanh Hoa 2024-04-29 15:59:45 +07:00
parent 4bdbaab471
commit 6f8e5beefa
5 changed files with 6 additions and 6 deletions

View file

@ -82,8 +82,8 @@ func showAttributeCounts(ns nodeSet) {
} }
} }
var keys []string
var maxlength int var maxlength int
keys := make([]string, 0, len(attrcount))
for key := range attrcount { for key := range attrcount {
keys = append(keys, key) keys = append(keys, key)
if len(key) > maxlength { if len(key) > maxlength {

View file

@ -76,7 +76,7 @@ func blockTestCmd(ctx *cli.Context) error {
} }
// Run them in order // Run them in order
var keys []string keys := make([]string, 0, len(tests))
for key := range tests { for key := range tests {
keys = append(keys, key) keys = append(keys, key)
} }

View file

@ -282,7 +282,7 @@ func readInput(ctx *cli.Context) (*bbInput, error) {
} }
// Deserialize rlp txs and ommers // Deserialize rlp txs and ommers
var ( var (
ommers = []*types.Header{} ommers = make([]*types.Header, 0, len(inputData.OmmersRlp))
txs = []*types.Transaction{} txs = []*types.Transaction{}
) )
if inputData.TxRlp != "" { if inputData.TxRlp != "" {

View file

@ -832,7 +832,7 @@ func decreaseKey(key []byte) []byte {
func BenchmarkProve(b *testing.B) { func BenchmarkProve(b *testing.B) {
trie, vals := randomTrie(100) trie, vals := randomTrie(100)
var keys []string keys := make([]string, 0, len(vals))
for k := range vals { for k := range vals {
keys = append(keys, k) keys = append(keys, k)
} }
@ -850,8 +850,8 @@ func BenchmarkProve(b *testing.B) {
func BenchmarkVerifyProof(b *testing.B) { func BenchmarkVerifyProof(b *testing.B) {
trie, vals := randomTrie(100) trie, vals := randomTrie(100)
root := trie.Hash() root := trie.Hash()
var keys []string
var proofs []*memorydb.Database var proofs []*memorydb.Database
keys := make([]string, 0, len(vals))
for k := range vals { for k := range vals {
keys = append(keys, k) keys = append(keys, k)
proof := memorydb.New() proof := memorydb.New()

View file

@ -164,7 +164,7 @@ func testAccessList(t *testing.T, vals []struct{ k, v string }) {
parent = root parent = root
trie, _ = New(TrieID(root), db) trie, _ = New(TrieID(root), db)
orig = trie.Copy() orig = trie.Copy()
var keys []string keys := make([]string, 0, 30)
for i := 0; i < 30; i++ { for i := 0; i < 30; i++ {
key := randBytes(32) key := randBytes(32)
keys = append(keys, string(key)) keys = append(keys, string(key))