You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-24 23:16:47 +02:00
#57 copy bytes
This commit is contained in:
39
feature_pool.go
Normal file
39
feature_pool.go
Normal file
@ -0,0 +1,39 @@
|
||||
package jsoniter
|
||||
|
||||
func (cfg *frozenConfig) borrowStream() *Stream {
|
||||
select {
|
||||
case stream := <-cfg.streamPool:
|
||||
stream.Reset(nil)
|
||||
return stream
|
||||
default:
|
||||
return NewStream(cfg, nil, 512)
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *frozenConfig) returnStream(stream *Stream) {
|
||||
select {
|
||||
case cfg.streamPool <- stream:
|
||||
return
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *frozenConfig) borrowIterator(data []byte) *Iterator {
|
||||
select {
|
||||
case iter := <- cfg.iteratorPool:
|
||||
iter.ResetBytes(data)
|
||||
return iter
|
||||
default:
|
||||
return ParseBytes(cfg, data)
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *frozenConfig) returnIterator(iter *Iterator) {
|
||||
select {
|
||||
case cfg.iteratorPool <- iter:
|
||||
return
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user