Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion store/smt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,28 @@ func (x *node) replaceChild(oldKey, newKey []byte) {
}

// copy() returns a shallow copy of the node
func (x *node) copy() *node { return &(*x) }
//
// The node struct is rebuilt field by field rather than dereferenced and
// re-addressed: `&(*x)` is simply `x` and returns the original pointer, and a
// plain `*x` struct copy would copy the protobuf MessageState embedded in
// lib.Node (a lock copy, reported by `go vet`). The byte slices and the *key
// are shared with the original, which is what "shallow" means here.
func (x *node) copy() *node {
if x == nil {
return nil
}
return &node{
Key: x.Key,
Node: lib.Node{
Value: x.Node.Value,
LeftChildKey: x.Node.LeftChildKey,
RightChildKey: x.Node.RightChildKey,
Key: x.Node.Key,
Bitmask: x.Node.Bitmask,
},
delete: x.delete,
}
}

// NODE LIST CODE BELOW

Expand Down