diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2022-11-07 16:55:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 16:55:53 +0100 |
commit | f37bb587b6634435afb5069b2101cb4e0ff78d63 (patch) | |
tree | 9e6ace8591fff4e95f982304842f0bf8512bd612 /utils/sync/bufio.go | |
parent | 652bc83fe45c114440de41d7e0fecf3e4b9e517d (diff) | |
parent | a2c309de872dc18053acb186b1ec125d1f723a90 (diff) | |
download | go-git-f37bb587b6634435afb5069b2101cb4e0ff78d63.tar.gz |
Merge pull request #608 from pjbgf/optimise-zlib-reader
Optimise zlib reader and consolidate sync.Pools
Diffstat (limited to 'utils/sync/bufio.go')
-rw-r--r-- | utils/sync/bufio.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/utils/sync/bufio.go b/utils/sync/bufio.go new file mode 100644 index 0000000..5009ea8 --- /dev/null +++ b/utils/sync/bufio.go @@ -0,0 +1,29 @@ +package sync + +import ( + "bufio" + "io" + "sync" +) + +var bufioReader = sync.Pool{ + New: func() interface{} { + return bufio.NewReader(nil) + }, +} + +// GetBufioReader returns a *bufio.Reader that is managed by a sync.Pool. +// Returns a bufio.Reader that is resetted with reader and ready for use. +// +// After use, the *bufio.Reader should be put back into the sync.Pool +// by calling PutBufioReader. +func GetBufioReader(reader io.Reader) *bufio.Reader { + r := bufioReader.Get().(*bufio.Reader) + r.Reset(reader) + return r +} + +// PutBufioReader puts reader back into its sync.Pool. +func PutBufioReader(reader *bufio.Reader) { + bufioReader.Put(reader) +} |