1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

use sync.Pool

This commit is contained in:
Tao Wen
2018-02-22 10:29:29 +08:00
parent d346ea6e55
commit a3fdd37b9a
4 changed files with 23 additions and 32 deletions

View File

@ -5,6 +5,7 @@ import (
"io"
"unsafe"
"github.com/v2pro/plz/reflect2"
"sync"
)
// Config customize how the API should behave.
@ -66,8 +67,16 @@ func (cfg Config) Froze() API {
objectFieldMustBeSimpleString: cfg.ObjectFieldMustBeSimpleString,
onlyTaggedField: cfg.OnlyTaggedField,
disallowUnknownFields: cfg.DisallowUnknownFields,
streamPool: make(chan *Stream, 16),
iteratorPool: make(chan *Iterator, 16),
}
api.streamPool = &sync.Pool{
New: func() interface{} {
return NewStream(api, nil, 512)
},
}
api.iteratorPool = &sync.Pool{
New: func() interface{} {
return NewIterator(api)
},
}
api.initCache()
encoderExtension := EncoderExtension{}