return e
}
func putBufferedEncoder(e *Encoder) {
+ if cap(e.s.availBuffer) > 64<<10 {
+ e.s.availBuffer = nil // avoid pinning arbitrarily large amounts of memory
+ }
+
// Recycle large buffers only if sufficiently utilized.
// If a buffer is under-utilized enough times sequentially,
// then it is discarded, ensuring that a single large buffer
}
}
func putStreamingEncoder(e *Encoder) {
+ if cap(e.s.availBuffer) > 64<<10 {
+ e.s.availBuffer = nil // avoid pinning arbitrarily large amounts of memory
+ }
if _, ok := e.s.wr.(*bytes.Buffer); ok {
+ e.s.wr, e.s.Buf = nil, nil // avoid pinning the provided bytes.Buffer
bytesBufferEncoderPool.Put(e)
} else {
+ e.s.wr = nil // avoid pinning the provided io.Writer
if cap(e.s.Buf) > 64<<10 {
e.s.Buf = nil // avoid pinning arbitrarily large amounts of memory
}
return d
}
func putBufferedDecoder(d *Decoder) {
+ d.s.buf = nil // avoid pinning the provided buffer
bufferedDecoderPool.Put(d)
}
}
func putStreamingDecoder(d *Decoder) {
if _, ok := d.s.rd.(*bytes.Buffer); ok {
+ d.s.rd, d.s.buf = nil, nil // avoid pinning the provided bytes.Buffer
bytesBufferDecoderPool.Put(d)
} else {
+ d.s.rd = nil // avoid pinning the provided io.Reader
if cap(d.s.buf) > 64<<10 {
d.s.buf = nil // avoid pinning arbitrarily large amounts of memory
}