Reduce allocations of buffer for reused readers

This commit is contained in:
Mike Faraponov 2021-03-01 19:42:42 +02:00 committed by GitHub
parent 729edfbcfe
commit 87d8f4575c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -33,6 +33,9 @@ func NewReader(src io.Reader) *Reader {
func (r *Reader) Reset(src io.Reader) error { func (r *Reader) Reset(src io.Reader) error {
decoderStateInit(r) decoderStateInit(r)
r.src = src r.src = src
if r.buf != nil {
return nil
}
r.buf = make([]byte, readBufSize) r.buf = make([]byte, readBufSize)
return nil return nil
} }