lib/scanner: Avoid per iteration allocations in Blocks()

Resetting the io.LimitReader is better than creating a new one on every
iteration.
This commit is contained in:
Jakob Borg 2017-01-18 18:43:00 +01:00
parent 4c8aa14e07
commit 68f1c6ccab

View File

@ -45,8 +45,9 @@ func Blocks(r io.Reader, blocksize int, sizehint int64, counter Counter) ([]prot
buf := make([]byte, 32<<10)
var offset int64
lr := io.LimitReader(r, int64(blocksize)).(*io.LimitedReader)
for {
lr := io.LimitReader(r, int64(blocksize))
lr.N = int64(blocksize)
n, err := io.CopyBuffer(mhf, lr, buf)
if err != nil {
return nil, err