Commit 6c878f73 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Discard slices that are not a power of 2 early.

parent 5f6695ad
...@@ -120,10 +120,16 @@ func (me *BufferPool) AllocBuffer(size uint32) []byte { ...@@ -120,10 +120,16 @@ func (me *BufferPool) AllocBuffer(size uint32) []byte {
// AllocBuffer. It is not an error to call FreeBuffer() on a slice // AllocBuffer. It is not an error to call FreeBuffer() on a slice
// obtained elsewhere. // obtained elsewhere.
func (me *BufferPool) FreeBuffer(slice []byte) { func (me *BufferPool) FreeBuffer(slice []byte) {
if cap(slice) < PAGESIZE { sz := cap(slice)
if sz < PAGESIZE {
return
}
exp := IntToExponent(sz)
rounded := 1 << exp
if rounded != sz {
return return
} }
slice = slice[:cap(slice)] slice = slice[:sz]
key := uintptr(unsafe.Pointer(&slice[0])) key := uintptr(unsafe.Pointer(&slice[0]))
me.lock.Lock() me.lock.Lock()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment