mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
trie: don't keep []byte from DB load around
Nodes decoded from a DB load kept hashes and values as sub-slices of the DB value. This can be a problem because loading from leveldb often returns []byte with a cap that's larger than necessary, increasing memory usage.
This commit is contained in:
parent
2819f1c324
commit
36e4f76cad
1 changed files with 3 additions and 3 deletions
|
|
@ -130,7 +130,7 @@ func decodeShort(hash, buf, elems []byte) (node, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid value node: %v", err)
|
return nil, fmt.Errorf("invalid value node: %v", err)
|
||||||
}
|
}
|
||||||
return &shortNode{key, valueNode(val), hash, false}, nil
|
return &shortNode{key, append(valueNode{}, val...), hash, false}, nil
|
||||||
}
|
}
|
||||||
r, _, err := decodeRef(rest)
|
r, _, err := decodeRef(rest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -153,7 +153,7 @@ func decodeFull(hash, buf, elems []byte) (*fullNode, error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
if len(val) > 0 {
|
if len(val) > 0 {
|
||||||
n.Children[16] = valueNode(val)
|
n.Children[16] = append(valueNode{}, val...)
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +179,7 @@ func decodeRef(buf []byte) (node, []byte, error) {
|
||||||
// empty node
|
// empty node
|
||||||
return nil, rest, nil
|
return nil, rest, nil
|
||||||
case kind == rlp.String && len(val) == 32:
|
case kind == rlp.String && len(val) == 32:
|
||||||
return hashNode(val), rest, nil
|
return append(hashNode{}, val...), rest, nil
|
||||||
default:
|
default:
|
||||||
return nil, nil, fmt.Errorf("invalid RLP string size %d (want 0 or 32)", len(val))
|
return nil, nil, fmt.Errorf("invalid RLP string size %d (want 0 or 32)", len(val))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue