diff options
| author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
| commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
| tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/json-iterator/go/pool.go | |
| parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
| download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip | |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/json-iterator/go/pool.go')
| -rw-r--r-- | vendor/github.com/json-iterator/go/pool.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/github.com/json-iterator/go/pool.go b/vendor/github.com/json-iterator/go/pool.go new file mode 100644 index 0000000..e2389b5 --- /dev/null +++ b/vendor/github.com/json-iterator/go/pool.go | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | package jsoniter | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "io" | ||
| 5 | ) | ||
| 6 | |||
| 7 | // IteratorPool a thread safe pool of iterators with same configuration | ||
| 8 | type IteratorPool interface { | ||
| 9 | BorrowIterator(data []byte) *Iterator | ||
| 10 | ReturnIterator(iter *Iterator) | ||
| 11 | } | ||
| 12 | |||
| 13 | // StreamPool a thread safe pool of streams with same configuration | ||
| 14 | type StreamPool interface { | ||
| 15 | BorrowStream(writer io.Writer) *Stream | ||
| 16 | ReturnStream(stream *Stream) | ||
| 17 | } | ||
| 18 | |||
| 19 | func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream { | ||
| 20 | stream := cfg.streamPool.Get().(*Stream) | ||
| 21 | stream.Reset(writer) | ||
| 22 | return stream | ||
| 23 | } | ||
| 24 | |||
| 25 | func (cfg *frozenConfig) ReturnStream(stream *Stream) { | ||
| 26 | stream.out = nil | ||
| 27 | stream.Error = nil | ||
| 28 | stream.Attachment = nil | ||
| 29 | cfg.streamPool.Put(stream) | ||
| 30 | } | ||
| 31 | |||
| 32 | func (cfg *frozenConfig) BorrowIterator(data []byte) *Iterator { | ||
| 33 | iter := cfg.iteratorPool.Get().(*Iterator) | ||
| 34 | iter.ResetBytes(data) | ||
| 35 | return iter | ||
| 36 | } | ||
| 37 | |||
| 38 | func (cfg *frozenConfig) ReturnIterator(iter *Iterator) { | ||
| 39 | iter.Error = nil | ||
| 40 | iter.Attachment = nil | ||
| 41 | cfg.iteratorPool.Put(iter) | ||
| 42 | } | ||