From eae3c603baaad41f9aef7f5605aca62532c29d60 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Thu, 26 Mar 2020 16:18:38 +0100 Subject: [PATCH] zstd: Reduce allocations when decoding from a bytes.Buffer Fixes #248 --- zstd/decoder.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zstd/decoder.go b/zstd/decoder.go index 86553c2c36..2340255051 100644 --- a/zstd/decoder.go +++ b/zstd/decoder.go @@ -169,7 +169,12 @@ func (d *Decoder) Reset(r io.Reader) error { println("*bytes.Buffer detected, doing sync decode, len:", bb.Len()) } b := bb.Bytes() - dst, err := d.DecodeAll(b, nil) + var dst []byte + if cap(d.current.b) > 0 { + dst = d.current.b + } + + dst, err := d.DecodeAll(b, dst[:0]) if err == nil { err = io.EOF }