diff options
author | 2021-11-13 12:29:08 +0100 | |
---|---|---|
committer | 2021-11-13 12:29:08 +0100 | |
commit | 829a934d23ab221049b4d54926305d8d5d64c9ad (patch) | |
tree | f4e382b289c113d3ba8a3c7a183507a5609c46c0 /vendor/codeberg.org/gruf/go-pools/fastpath.go | |
parent | smtp + email confirmation (#285) (diff) | |
download | gotosocial-829a934d23ab221049b4d54926305d8d5d64c9ad.tar.xz |
update dependencies (#296)
Diffstat (limited to 'vendor/codeberg.org/gruf/go-pools/fastpath.go')
-rw-r--r-- | vendor/codeberg.org/gruf/go-pools/fastpath.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-pools/fastpath.go b/vendor/codeberg.org/gruf/go-pools/fastpath.go new file mode 100644 index 000000000..eb76f03e4 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-pools/fastpath.go @@ -0,0 +1,46 @@ +package pools + +import ( + "sync" + + "codeberg.org/gruf/go-fastpath" +) + +// PathBuilderPool is a pooled allocator for fastpath.Builder objects +type PathBuilderPool interface { + // Get fetches a fastpath.Builder from pool + Get() *fastpath.Builder + + // Put places supplied fastpath.Builder back in pool + Put(*fastpath.Builder) +} + +// NewPathBuilderPool returns a newly instantiated fastpath.Builder pool +func NewPathBuilderPool(size int) PathBuilderPool { + return &pathBuilderPool{ + pool: sync.Pool{ + New: func() interface{} { + return &fastpath.Builder{B: make([]byte, 0, size)} + }, + }, + size: size, + } +} + +// pathBuilderPool is our implementation of PathBuilderPool +type pathBuilderPool struct { + pool sync.Pool + size int +} + +func (p *pathBuilderPool) Get() *fastpath.Builder { + return p.pool.Get().(*fastpath.Builder) +} + +func (p *pathBuilderPool) Put(pb *fastpath.Builder) { + if pb.Cap() < p.size { + return + } + pb.Reset() + p.pool.Put(pb) +} |