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

feat: reduce blake2b allocations by special-casing the 256/512 variants #126

Merged
merged 1 commit into from
May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ func sumBlake2s(data []byte, size int) ([]byte, error) {
return d[:], nil
}
func sumBlake2b(data []byte, size int) ([]byte, error) {
// special case these lengths to avoid allocations.
switch size {
case 32:
hash := blake2b.Sum256(data)
return hash[:], nil
case 64:
hash := blake2b.Sum512(data)
return hash[:], nil
}

// Ok, allocate away.
hasher, err := blake2b.New(&blake2b.Config{Size: uint8(size)})
if err != nil {
return nil, err
Expand Down