nmt icon indicating copy to clipboard operation
nmt copied to clipboard

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

Open odeke-em opened this issue 1 year ago • 0 comments

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...) 

odeke-em avatar Sep 16 '24 20:09 odeke-em