Skip to content

Commit

Permalink
Chore: Remove one allocate per hash by using generics (algorand#5829)
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti authored Nov 17, 2023
1 parent 7361679 commit b359a5f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion hashes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func TestHashSum(t *testing.T) {

dgst := HashObj(TestingHashable{})
a.Equal(GenericHashObj(h, TestingHashable{}), dgst[:])

}

func TestEmptyHash(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Hashable interface {
}

// HashRep appends the correct hashid before the message to be hashed.
func HashRep(h Hashable) []byte {
func HashRep[H Hashable](h H) []byte {
hashid, data := h.ToBeHashed()
return append([]byte(hashid), data...)
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func Hash(data []byte) Digest {
}

// HashObj computes a hash of a Hashable object and its type
func HashObj(h Hashable) Digest {
func HashObj[H Hashable](h H) Digest {
return Hash(HashRep(h))
}

Expand Down

0 comments on commit b359a5f

Please sign in to comment.