Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
odeke-em opened this issue Sep 16, 2024 · 0 comments

Comments

@odeke-em
Copy link
Contributor

If we look at

nmt/hasher.go

Lines 157 to 159 in 29e9433

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

we notice this code

nmt/hasher.go

Line 159 in 29e9433

digest := append(append(emptyNs, emptyNs...), h...)

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...) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant