Skip to content

Commit

Permalink
Reduce allocations for Reset()
Browse files Browse the repository at this point in the history
  • Loading branch information
K1li4nL committed Mar 28, 2024
1 parent cb72df8 commit 009ea8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions xof/blake2xb/blake.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ func (x *xof) Reseed() {
}

func (x *xof) Reset() {
y := New(x.seed)
x.impl = y.(*xof).impl
x.impl.Reset()
if len(x.seed) > blake2b.Size {
x.impl.Write(x.seed[blake2b.Size:])
}
}

func (x *xof) XORKeyStream(dst, src []byte) {
Expand Down
6 changes: 4 additions & 2 deletions xof/blake2xs/blake.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ func (x *xof) Reseed() {
}

func (x *xof) Reset() {
y := New(x.seed)
x.impl = y.(*xof).impl
x.impl.Reset()
if len(x.seed) > blake2s.Size {
x.impl.Write(x.seed[blake2s.Size:])
}
}

func (x *xof) XORKeyStream(dst, src []byte) {
Expand Down

0 comments on commit 009ea8c

Please sign in to comment.