Do not drop on the floor small buffers

Currently if a buffer from the buffer is too small to satisfy its request then we simply drop it and allocate a new one.

This change puts it back in the pool and then allocates a new one.
pull/9461/head
Carlo Alberto Ferraris 2018-02-17 20:41:07 +09:00 committed by GitHub
parent 6d008c3453
commit 228e17d79b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -13,6 +13,7 @@ func getBuf(size int) *[]byte {
}
buf := x.(*[]byte)
if cap(*buf) < size {
bufPool.Put(x)
b := make([]byte, size)
return &b
}