celestiaorg / nmt

Namespaced Merkle Tree
Apache License 2.0
117 stars 42 forks source link

NmtHasher.EmptyRoot has unnecessary double append instead of creating slice with double capacity #273

Open odeke-em opened 2 months ago

odeke-em commented 2 months ago

If we look at https://github.com/celestiaorg/nmt/blob/29e9433bd79eed40462000626ef987c91b0cf523/hasher.go#L157-L159

we notice this code https://github.com/celestiaorg/nmt/blob/29e9433bd79eed40462000626ef987c91b0cf523/hasher.go#L159

but that code could be made clearer, simpler and even faster (if in hot loop) by

emptyNs2X := bytes.Repeat([]byte{0}, int(n.NamespaceLen)*2) 
h := n.baseHasher.Sum(nil) 
digest := append(emptyNs2X, h...)