From 014520c7fd5e84bdd3d75352c4797c7402c45631 Mon Sep 17 00:00:00 2001 From: unclejack Date: Mon, 29 Jun 2015 23:27:54 +0300 Subject: [PATCH] daemon: lower allocations Signed-off-by: Cristian Staretu --- pools/pools.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pools/pools.go b/pools/pools.go index f366fa6..c34ea92 100644 --- a/pools/pools.go +++ b/pools/pools.go @@ -57,6 +57,14 @@ func (bufPool *BufioReaderPool) Put(b *bufio.Reader) { bufPool.pool.Put(b) } +// Copy is a convenience wrapper which uses a buffer to avoid allocation in io.Copy +func Copy(dst io.Writer, src io.Reader) (written int64, err error) { + buf := BufioReader32KPool.Get(src) + written, err = io.Copy(dst, buf) + BufioReader32KPool.Put(buf) + return +} + // NewReadCloserWrapper returns a wrapper which puts the bufio.Reader back // into the pool and closes the reader if it's an io.ReadCloser. func (bufPool *BufioReaderPool) NewReadCloserWrapper(buf *bufio.Reader, r io.Reader) io.ReadCloser {