Browse Source

Pregrow buffers on Get

DarthSim 6 years ago
parent
commit
d63f0d5cbe
2 changed files with 4 additions and 4 deletions
  1. 4 0
      bufpool.go
  2. 0 4
      download.go

+ 4 - 0
bufpool.go

@@ -118,6 +118,10 @@ func (p *bufPool) Get(size int) *bytes.Buffer {
 
 	buf.Reset()
 
+	if size > 0 && size > buf.Cap() {
+		buf.Grow(size)
+	}
+
 	return buf
 }
 

+ 0 - 4
download.go

@@ -136,10 +136,6 @@ func readAndCheckImage(ctx context.Context, res *http.Response) (context.Context
 		downloadBufPool.Put(buf)
 	}
 
-	if contentLength > buf.Cap() {
-		buf.Grow(contentLength - buf.Len())
-	}
-
 	body := res.Body
 
 	if conf.MaxSrcFileSize > 0 {