diff --git a/lib/trie/node.go b/lib/trie/node.go index efe88c2df9..5d84e6fa0f 100644 --- a/lib/trie/node.go +++ b/lib/trie/node.go @@ -98,45 +98,28 @@ func (l *leaf) setGeneration(generation uint64) { func (b *branch) copy() node { b.Lock() defer b.Unlock() - cpy := &branch{ - key: make([]byte, len(b.key)), - children: [16]node{}, - value: nil, + return &branch{ + key: b.key, + children: b.children, + value: b.value, dirty: b.dirty, - hash: make([]byte, len(b.hash)), - encoding: make([]byte, len(b.encoding)), + hash: b.hash, + encoding: b.encoding, generation: b.generation, } - copy(cpy.key, b.key) - copy(cpy.children[:], b.children[:]) // copy interface pointers - - // nil and []byte{} are encoded differently, watch out! - if b.value != nil { - cpy.value = make([]byte, len(b.value)) - copy(cpy.value, b.value) - } - - copy(cpy.hash, b.hash) - copy(cpy.encoding, b.encoding) - return cpy } func (l *leaf) copy() node { l.Lock() defer l.Unlock() - cpy := &leaf{ - key: make([]byte, len(l.key)), - value: make([]byte, len(l.value)), + return &leaf{ + key: l.key, + value: l.value, dirty: l.dirty, - hash: make([]byte, len(l.hash)), - encoding: make([]byte, len(l.encoding)), + hash: l.hash, + encoding: l.encoding, generation: l.generation, } - copy(cpy.key, l.key) - copy(cpy.value, l.value) - copy(cpy.hash, l.hash) - copy(cpy.encoding, l.encoding) - return cpy } func (b *branch) setEncodingAndHash(enc, hash []byte) {