rename initialize to make

This commit is contained in:
Krasi Georgiev 2018-02-19 14:38:40 +02:00
parent 9878d66484
commit 9b7f0cfa88

View file

@ -23,13 +23,13 @@ import (
type Pool struct { type Pool struct {
buckets []sync.Pool buckets []sync.Pool
sizes []int sizes []int
// initialize is the function used to create an empty slice when none exist yet. // make is the function used to create an empty slice when none exist yet.
initialize func(int) interface{} make func(int) interface{}
} }
// New returns a new Pool with size buckets for minSize to maxSize // New returns a new Pool with size buckets for minSize to maxSize
// increasing by the given factor. // increasing by the given factor.
func New(minSize, maxSize int, factor float64, newFunc func(int) interface{}) *Pool { func New(minSize, maxSize int, factor float64, makeFunc func(int) interface{}) *Pool {
if minSize < 1 { if minSize < 1 {
panic("invalid minimum pool size") panic("invalid minimum pool size")
} }
@ -47,9 +47,9 @@ func New(minSize, maxSize int, factor float64, newFunc func(int) interface{}) *P
} }
p := &Pool{ p := &Pool{
buckets: make([]sync.Pool, len(sizes)), buckets: make([]sync.Pool, len(sizes)),
sizes: sizes, sizes: sizes,
initialize: newFunc, make: makeFunc,
} }
return p return p
@ -63,11 +63,11 @@ func (p *Pool) Get(sz int) interface{} {
} }
b := p.buckets[i].Get() b := p.buckets[i].Get()
if b == nil { if b == nil {
b = p.initialize(bktSize) b = p.make(bktSize)
} }
return b return b
} }
return p.initialize(sz) return p.make(sz)
} }
// Put adds a slice to the right bucket in the pool. // Put adds a slice to the right bucket in the pool.