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
keys := make([]string, 0, len(attrcount))
for key := range attrcount {
keys = append(keys, key)
if len(key) > maxlength {

View file

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

View file

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

View file

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

View file

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