diff --git a/pool.go b/pool.go index 6a032991834559d88886d7e9ef8d13e27ae63be4..6e7a8c822acd68a9ba3d7073a820eb33bdae8f4c 100644 --- a/pool.go +++ b/pool.go @@ -48,15 +48,18 @@ type BufferPool struct { // values returned by Get. // // If no suitable buffer exists in the pool, Get creates one. -func (p *BufferPool) Get(length uint32) []byte { +func (p *BufferPool) Get(length int) []byte { if length == 0 { return nil } - idx := nextLogBase2(length) + if length > MaxLength { + return make([]byte, length) + } + idx := nextLogBase2(uint32(length)) if buf := p.pools[idx].Get(); buf != nil { - return buf.([]byte)[:length] + return buf.([]byte)[:uint32(length)] } - return make([]byte, 1<= %d, got %d", j, len(v)) } ch <- v @@ -115,7 +115,7 @@ func TestPoolStressByteSlicePool(t *testing.T) { func BenchmarkPool(b *testing.B) { var p BufferPool b.RunParallel(func(pb *testing.PB) { - i := uint32(7) + i := 7 for pb.Next() { if i > 1<<20 { i = 7 @@ -135,7 +135,7 @@ func BenchmarkPoolOverlflow(b *testing.B) { bufs := make([][]byte, 2100) for pow := uint32(0); pow < 21; pow++ { for i := 0; i < 100; i++ { - bufs = append(bufs, p.Get(uint32(1<