diff --git a/jx.go b/jx.go index 24996eb..fc59b63 100644 --- a/jx.go +++ b/jx.go @@ -19,6 +19,11 @@ var ( return &Encoder{} }, } + writerPool = &sync.Pool{ + New: func() interface{} { + return &Writer{} + }, + } decPool = &sync.Pool{ New: func() interface{} { return &Decoder{} @@ -48,3 +53,14 @@ func PutEncoder(e *Encoder) { e.SetIdent(0) encPool.Put(e) } + +// GetWriter returns *Writer from pool. +func GetWriter() *Writer { + return encPool.Get().(*Writer) +} + +// PutWriter puts *Writer to pool +func PutWriter(e *Writer) { + e.Reset() + encPool.Put(e) +}