Skip to content

Commit

Permalink
feat: add Writer pool
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jan 20, 2022
1 parent 4f7480a commit 29f5912
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions jx.go
Expand Up @@ -19,6 +19,11 @@ var (
return &Encoder{}
},
}
writerPool = &sync.Pool{
New: func() interface{} {
return &Writer{}
},
}
decPool = &sync.Pool{
New: func() interface{} {
return &Decoder{}
Expand Down Expand Up @@ -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)
}

0 comments on commit 29f5912

Please sign in to comment.