mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-01-20 16:42:51 +08:00
46b5d73382
Automatic merge from submit-queue (batch tested with PRs 57122, 57142, 57016, 56927, 56678). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. bump(13f864): github.com/json-iterator/go: use ConfigCompatibleWithStandardLibrary Jsoniter in `ConfigFastest` mode does not support escape characters in object keys, whereas `ConfigCompatibleWithStandardLibrary` does. Fixes kubernetes/kubernetes#56018 Related kubernetes/kubernetes#56055 Benchmark results: ``` BenchmarkDecodeIntoJSON-4 30000 48522 ns/op 3792 B/op 63 allocs/op BenchmarkDecodeIntoJSONCodecGenConfigFast-4 100000 17409 ns/op 4524 B/op 96 allocs/op BenchmarkDecodeIntoJSONCodecGenConfigCompatibleWithStandardLibrary-4 100000 18617 ns/op 4924 B/op 121 allocs/op ``` /assign sttts thockin mfojtik Kubernetes-commit: 135d58b3941fac99ae0426e18cbda266b83ca49e
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
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
|
|
stream.Attachment = 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
|
|
iter.Attachment = nil
|
|
select {
|
|
case cfg.iteratorPool <- iter:
|
|
return
|
|
default:
|
|
return
|
|
}
|
|
}
|