1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-24 23:16:47 +02:00

document how to get best performance

This commit is contained in:
Tao Wen
2017-06-17 17:14:34 +08:00
parent f29fe7407e
commit 50e4910c63
3 changed files with 64 additions and 18 deletions

View File

@ -1,16 +1,18 @@
package jsoniter
func (cfg *frozenConfig) borrowStream() *Stream {
import "io"
func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream {
select {
case stream := <-cfg.streamPool:
stream.Reset(nil)
stream.Reset(writer)
return stream
default:
return NewStream(cfg, nil, 512)
return NewStream(cfg, writer, 512)
}
}
func (cfg *frozenConfig) returnStream(stream *Stream) {
func (cfg *frozenConfig) ReturnStream(stream *Stream) {
select {
case cfg.streamPool <- stream:
return
@ -19,7 +21,7 @@ func (cfg *frozenConfig) returnStream(stream *Stream) {
}
}
func (cfg *frozenConfig) borrowIterator(data []byte) *Iterator {
func (cfg *frozenConfig) BorrowIterator(data []byte) *Iterator {
select {
case iter := <- cfg.iteratorPool:
iter.ResetBytes(data)
@ -29,7 +31,7 @@ func (cfg *frozenConfig) borrowIterator(data []byte) *Iterator {
}
}
func (cfg *frozenConfig) returnIterator(iter *Iterator) {
func (cfg *frozenConfig) ReturnIterator(iter *Iterator) {
select {
case cfg.iteratorPool <- iter:
return