package bufpool

import (
	
	
)

var thePool bufPool

// Get retrieves a buffer of the appropriate length from the buffer pool or
// allocates a new one. Get may choose to ignore the pool and treat it as empty.
// Callers should not assume any relation between values passed to Put and the
// values returned by Get.
//
// If no suitable buffer exists in the pool, Get creates one.
func ( int) *Buffer {
	return thePool.Get()
}

// Put returns a buffer to the buffer pool.
func ( *Buffer) {
	thePool.Put()
}

type bufPool struct {
	pools [steps]sync.Pool
}

func ( *bufPool) ( int) *Buffer {
	if  > maxPoolSize {
		return NewBuffer(make([]byte, ))
	}

	 := index()
	if  := .pools[].Get();  != nil {
		 := .(*Buffer)
		unlock()
		if  > .Cap() {
			log.Println(, .Len(), .Cap(), .String())
		}
		.buf = .buf[:]
		return 
	}

	 := make([]byte, , indexSize())
	return NewBuffer()
}

func ( *bufPool) ( *Buffer) {
	 := .Cap()
	if  > maxPoolSize ||  < minSize {
		return // drop it
	}

	 := prevIndex()
	lock()
	.pools[].Put()
}

func ( *Buffer) {
	.buf = .buf[:cap(.buf)]
	.off = cap(.buf) + 1
}

func ( *Buffer) {
	.off = 0
}