Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 9d6ad92

Browse files
committed
Cleanup buf usage
License: MIT Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 8cdd6f4 commit 9d6ad92

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

buzhash.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,21 @@ func (b *Buzhash) NextBytes() ([]byte, error) {
3737
return nil, b.err
3838
}
3939

40-
buf := b.buf
41-
n, err := io.ReadFull(b.r, buf[b.n:])
40+
n, err := io.ReadFull(b.r, b.buf[b.n:])
4241
if err != nil {
4342
if err == io.ErrUnexpectedEOF || err == io.EOF {
4443
if b.n+n < buzMin {
4544
b.err = io.EOF
4645
res := make([]byte, b.n+n)
47-
copy(res, buf)
46+
copy(res, b.buf)
4847

4948
pool.Put(b.buf)
5049
b.buf = nil
5150
return res, nil
5251
}
5352
} else {
5453
b.err = err
55-
pool.Put(buf)
54+
pool.Put(b.buf)
5655
b.buf = nil
5756
return nil, err
5857
}
@@ -64,21 +63,21 @@ func (b *Buzhash) NextBytes() ([]byte, error) {
6463

6564
for ; i < buzMin; i++ {
6665
state = bits.RotateLeft32(state, 1)
67-
state = state ^ bytehash[buf[i]]
66+
state = state ^ bytehash[b.buf[i]]
6867
}
6968

70-
if b.n+n > len(buf) {
69+
if b.n+n > len(b.buf) {
7170
panic("this is impossible, but gives +9 to performance")
7271
}
7372

7473
for ; state&buzMask != 0 && i < b.n+n; i++ {
75-
state = bits.RotateLeft32(state, 1) ^ bytehash[buf[i-32]] ^ bytehash[buf[i]]
74+
state = bits.RotateLeft32(state, 1) ^ bytehash[b.buf[i-32]] ^ bytehash[b.buf[i]]
7675
}
7776

7877
res := make([]byte, i)
7978
copy(res, b.buf)
8079

81-
b.n = copy(b.buf, buf[i:b.n+n])
80+
b.n = copy(b.buf, b.buf[i:b.n+n])
8281

8382
return res, nil
8483
}

0 commit comments

Comments
 (0)