Files
old-backend/services/location/mapbox_lib/pools.go
2023-10-12 05:23:34 +02:00

32 lines
549 B
Go

package mapbox
import (
"bytes"
"sync"
)
type noCopy struct{}
func (*noCopy) Lock() {}
func (*noCopy) Unlock() {}
type stringsBufferPool struct {
noCopy noCopy
p sync.Pool
}
func newStringsBufferPool() *stringsBufferPool {
return &stringsBufferPool{p: sync.Pool{New: func() interface{} {
return &bytes.Buffer{}
}}}
}
func (pool *stringsBufferPool) acquireStringsBuilder() *bytes.Buffer {
return pool.p.Get().(*bytes.Buffer)
}
func (pool *stringsBufferPool) releaseStringsBuilder(b *bytes.Buffer) {
b.Reset()
pool.p.Put(b)
}