Files
kopia/repo/splitter/splitter_pool.go
2025-04-15 22:49:13 -07:00

31 lines
504 B
Go

package splitter
import (
"sync"
)
type recyclableSplitter struct {
Splitter
pool *sync.Pool
}
func (s recyclableSplitter) Close() {
s.Reset()
s.Splitter.Close()
s.pool.Put(s.Splitter)
}
// pooled returns a factory that recycles the splitters on Close().
func pooled(f Factory) Factory {
pool := &sync.Pool{}
return func() Splitter {
s := pool.Get()
if s == nil {
return recyclableSplitter{f(), pool}
}
return recyclableSplitter{s.(Splitter), pool} //nolint:forcetypeassert
}
}