Skip to content

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

@odeke-em

Description

@odeke-em

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions