Skip to content

Commit c39d00e

Browse files
authored
trie: using maps.Clone (#29419)
1 parent a382917 commit c39d00e

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

trie/sync_test.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package trie
1919
import (
2020
"bytes"
2121
"fmt"
22+
"maps"
2223
"math/rand"
2324
"testing"
2425

@@ -837,13 +838,6 @@ func testPivotMove(t *testing.T, scheme string, tiny bool) {
837838
tr.Update(key, val)
838839
states[string(key)] = common.CopyBytes(val)
839840
}
840-
copyStates = func(states map[string][]byte) map[string][]byte {
841-
cpy := make(map[string][]byte)
842-
for k, v := range states {
843-
cpy[k] = v
844-
}
845-
return cpy
846-
}
847841
)
848842
stateA := make(map[string][]byte)
849843
writeFn([]byte{0x01, 0x23}, nil, srcTrie, stateA)
@@ -866,7 +860,7 @@ func testPivotMove(t *testing.T, scheme string, tiny bool) {
866860
checkTrieContents(t, destDisk, scheme, srcTrie.Hash().Bytes(), stateA, true)
867861

868862
// Delete element to collapse trie
869-
stateB := copyStates(stateA)
863+
stateB := maps.Clone(stateA)
870864
srcTrie, _ = New(TrieID(rootA), srcTrieDB)
871865
deleteFn([]byte{0x02, 0x34}, srcTrie, stateB)
872866
deleteFn([]byte{0x13, 0x44}, srcTrie, stateB)
@@ -883,7 +877,7 @@ func testPivotMove(t *testing.T, scheme string, tiny bool) {
883877
checkTrieContents(t, destDisk, scheme, srcTrie.Hash().Bytes(), stateB, true)
884878

885879
// Add elements to expand trie
886-
stateC := copyStates(stateB)
880+
stateC := maps.Clone(stateB)
887881
srcTrie, _ = New(TrieID(rootB), srcTrieDB)
888882

889883
writeFn([]byte{0x01, 0x24}, stateA[string([]byte{0x01, 0x24})], srcTrie, stateC)
@@ -941,13 +935,6 @@ func testSyncAbort(t *testing.T, scheme string) {
941935
tr.Update(key, val)
942936
states[string(key)] = common.CopyBytes(val)
943937
}
944-
copyStates = func(states map[string][]byte) map[string][]byte {
945-
cpy := make(map[string][]byte)
946-
for k, v := range states {
947-
cpy[k] = v
948-
}
949-
return cpy
950-
}
951938
)
952939
var (
953940
stateA = make(map[string][]byte)
@@ -972,7 +959,7 @@ func testSyncAbort(t *testing.T, scheme string) {
972959
checkTrieContents(t, destDisk, scheme, srcTrie.Hash().Bytes(), stateA, true)
973960

974961
// Delete the element from the trie
975-
stateB := copyStates(stateA)
962+
stateB := maps.Clone(stateA)
976963
srcTrie, _ = New(TrieID(rootA), srcTrieDB)
977964
deleteFn(key, srcTrie, stateB)
978965

@@ -999,7 +986,7 @@ func testSyncAbort(t *testing.T, scheme string) {
999986
}})
1000987

1001988
// Add elements to expand trie
1002-
stateC := copyStates(stateB)
989+
stateC := maps.Clone(stateB)
1003990
srcTrie, _ = New(TrieID(rootB), srcTrieDB)
1004991

1005992
writeFn(key, val, srcTrie, stateC)

0 commit comments

Comments
 (0)