1
0
mirror of https://github.com/json-iterator/go.git synced 2025-01-17 18:44:50 +02:00
json-iterator/feature_pool.go

46 lines
735 B
Go
Raw Normal View History

2017-06-17 14:36:05 +08:00
package jsoniter
2017-06-17 22:42:11 +08:00
import (
"io"
)
2017-06-17 17:14:34 +08:00
func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream {
2017-06-17 14:36:05 +08:00
select {
case stream := <-cfg.streamPool:
2017-06-17 17:14:34 +08:00
stream.Reset(writer)
2017-06-17 14:36:05 +08:00
return stream
default:
2017-06-17 17:14:34 +08:00
return NewStream(cfg, writer, 512)
2017-06-17 14:36:05 +08:00
}
}
2017-06-17 17:14:34 +08:00
func (cfg *frozenConfig) ReturnStream(stream *Stream) {
stream.Error = nil
2017-06-17 14:36:05 +08:00
select {
case cfg.streamPool <- stream:
return
default:
return
}
}
2017-06-17 17:14:34 +08:00
func (cfg *frozenConfig) BorrowIterator(data []byte) *Iterator {
2017-06-17 14:36:05 +08:00
select {
2017-06-17 21:11:23 +08:00
case iter := <-cfg.iteratorPool:
2017-06-17 14:36:05 +08:00
iter.ResetBytes(data)
return iter
default:
return ParseBytes(cfg, data)
}
}
2017-06-17 17:14:34 +08:00
func (cfg *frozenConfig) ReturnIterator(iter *Iterator) {
iter.Error = nil
2017-06-17 14:36:05 +08:00
select {
case cfg.iteratorPool <- iter:
return
default:
return
}
}