mirror of
https://github.com/kubernetes/client-go.git
synced 2025-10-27 03:24:02 +00:00
Merge pull request #48287 from thockin/json-iterator
Automatic merge from submit-queue Use json-iterator instead of ugorji for JSON. @smarterclayton @wojtek-t Fixes #36120 xref #18762 ```release-note Switch JSON marshal/unmarshal to json-iterator library. Performance should be close to previous with no generated code. ``` Kubernetes-commit: 6a845c67f097cd76f9d90ab3c9c5b5603c70afe4
This commit is contained in:
57
vendor/github.com/json-iterator/go/feature_pool.go
generated
vendored
Normal file
57
vendor/github.com/json-iterator/go/feature_pool.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package jsoniter
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// IteratorPool a thread safe pool of iterators with same configuration
|
||||
type IteratorPool interface {
|
||||
BorrowIterator(data []byte) *Iterator
|
||||
ReturnIterator(iter *Iterator)
|
||||
}
|
||||
|
||||
// StreamPool a thread safe pool of streams with same configuration
|
||||
type StreamPool interface {
|
||||
BorrowStream(writer io.Writer) *Stream
|
||||
ReturnStream(stream *Stream)
|
||||
}
|
||||
|
||||
func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream {
|
||||
select {
|
||||
case stream := <-cfg.streamPool:
|
||||
stream.Reset(writer)
|
||||
return stream
|
||||
default:
|
||||
return NewStream(cfg, writer, 512)
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *frozenConfig) ReturnStream(stream *Stream) {
|
||||
stream.Error = nil
|
||||
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) {
|
||||
iter.Error = nil
|
||||
select {
|
||||
case cfg.iteratorPool <- iter:
|
||||
return
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user