trie: address comments from martin
This commit is contained in:
parent
04eb38396a
commit
25ae4e5d82
|
@ -53,8 +53,7 @@ func returnHasherToPool(h *hasher) {
|
||||||
hasherPool.Put(h)
|
hasherPool.Put(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// hash collapses a node down into a hash node, also returning a copy of the
|
// hash collapses a node down into a hash node.
|
||||||
// original node initialized with the computed hash to replace the original one.
|
|
||||||
func (h *hasher) hash(n node, force bool) node {
|
func (h *hasher) hash(n node, force bool) node {
|
||||||
// Return the cached hash if it's available
|
// Return the cached hash if it's available
|
||||||
if hash, _ := n.cache(); hash != nil {
|
if hash, _ := n.cache(); hash != nil {
|
||||||
|
@ -86,8 +85,8 @@ func (h *hasher) hash(n node, force bool) node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hashShortNodeChildren collapses the short node. The returned collapsed node
|
// hashShortNodeChildren returns a copy of the supplied shortNode, with its child
|
||||||
// holds a live reference to the Key, and must not be modified.
|
// being replaced by either the hash or an embedded node if the child is small.
|
||||||
func (h *hasher) hashShortNodeChildren(n *shortNode) *shortNode {
|
func (h *hasher) hashShortNodeChildren(n *shortNode) *shortNode {
|
||||||
var collapsed shortNode
|
var collapsed shortNode
|
||||||
collapsed.Key = hexToCompact(n.Key)
|
collapsed.Key = hexToCompact(n.Key)
|
||||||
|
@ -100,6 +99,8 @@ func (h *hasher) hashShortNodeChildren(n *shortNode) *shortNode {
|
||||||
return &collapsed
|
return &collapsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hashFullNodeChildren returns a copy of the supplied fullNode, with its child
|
||||||
|
// being replaced by either the hash or an embedded node if the child is small.
|
||||||
func (h *hasher) hashFullNodeChildren(n *fullNode) *fullNode {
|
func (h *hasher) hashFullNodeChildren(n *fullNode) *fullNode {
|
||||||
var children [17]node
|
var children [17]node
|
||||||
if h.parallel {
|
if h.parallel {
|
||||||
|
@ -133,10 +134,9 @@ func (h *hasher) hashFullNodeChildren(n *fullNode) *fullNode {
|
||||||
return &fullNode{flags: nodeFlag{}, Children: children}
|
return &fullNode{flags: nodeFlag{}, Children: children}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shortnodeToHash creates a hashNode from a shortNode. The supplied shortnode
|
// shortNodeToHash computes the hash of the given shortNode. The shortNode must
|
||||||
// should have hex-type Key, which will be converted (without modification)
|
// first be collapsed, with its key converted to compact form. If the RLP-encoded
|
||||||
// into compact form for RLP encoding.
|
// node data is smaller than 32 bytes, the node itself is returned.
|
||||||
// If the rlp data is smaller than 32 bytes, `nil` is returned.
|
|
||||||
func (h *hasher) shortnodeToHash(n *shortNode, force bool) node {
|
func (h *hasher) shortnodeToHash(n *shortNode, force bool) node {
|
||||||
n.encode(h.encbuf)
|
n.encode(h.encbuf)
|
||||||
enc := h.encodedBytes()
|
enc := h.encodedBytes()
|
||||||
|
@ -147,8 +147,8 @@ func (h *hasher) shortnodeToHash(n *shortNode, force bool) node {
|
||||||
return h.hashData(enc)
|
return h.hashData(enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fullnodeToHash is used to create a hashNode from a fullNode, (which
|
// fullnodeToHash computes the hash of the given fullNode. If the RLP-encoded
|
||||||
// may contain nil values)
|
// node data is smaller than 32 bytes, the node itself is returned.
|
||||||
func (h *hasher) fullnodeToHash(n *fullNode, force bool) node {
|
func (h *hasher) fullnodeToHash(n *fullNode, force bool) node {
|
||||||
n.encode(h.encbuf)
|
n.encode(h.encbuf)
|
||||||
enc := h.encodedBytes()
|
enc := h.encodedBytes()
|
||||||
|
|
Loading…
Reference in New Issue