From e43a46e9822a05dd0345a7676e03285ddf83205e Mon Sep 17 00:00:00 2001 From: "kim (grufwub)" Date: Sat, 11 Sep 2021 20:12:47 +0100 Subject: add git.iim.gay/grufwub/go-store for storage backend, replacing blob.Storage Signed-off-by: kim (grufwub) --- vendor/git.iim.gay/grufwub/go-bytes/pool.go | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 vendor/git.iim.gay/grufwub/go-bytes/pool.go (limited to 'vendor/git.iim.gay/grufwub/go-bytes/pool.go') diff --git a/vendor/git.iim.gay/grufwub/go-bytes/pool.go b/vendor/git.iim.gay/grufwub/go-bytes/pool.go new file mode 100644 index 000000000..edd6859c1 --- /dev/null +++ b/vendor/git.iim.gay/grufwub/go-bytes/pool.go @@ -0,0 +1,39 @@ +package bytes + +import ( + "bytes" + "sync" +) + +type SizedBufferPool struct { + pool sync.Pool + len int + cap int +} + +func (p *SizedBufferPool) Init(len, cap int) { + p.pool.New = func() interface{} { + buf := NewBuffer(make([]byte, len, cap)) + return &buf + } + p.len = len + p.cap = cap +} + +func (p *SizedBufferPool) Acquire() *bytes.Buffer { + return p.pool.Get().(*bytes.Buffer) +} + +func (p *SizedBufferPool) Release(buf *bytes.Buffer) { + // If not enough cap, ignore + if buf.Cap() < p.cap { + return + } + + // Set length to expected + buf.Reset() + buf.Grow(p.len) + + // Place in pool + p.pool.Put(buf) +} -- cgit v1.2.3