Browse Source

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

Resetting the io.LimitReader is better than creating a new one on every
iteration.
Jakob Borg 8 years ago
parent
commit
68f1c6ccab
1 changed files with 2 additions and 1 deletions
  1. 2 1
      lib/scanner/blocks.go

+ 2 - 1
lib/scanner/blocks.go

@@ -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