Simplify iobufpool usage

non-blocking
Jack Christensen 2022-06-18 17:46:49 -05:00
parent 60ecdda02e
commit 6b63ceee07
3 changed files with 3 additions and 11 deletions

View File

@ -37,9 +37,7 @@ func getPoolIdx(size int) int {
// Put returns buf to the pool. // Put returns buf to the pool.
func Put(buf []byte) { func Put(buf []byte) {
buf = buf[:cap(buf)] i := putPoolIdx(cap(buf))
i := putPoolIdx(len(buf))
if i < 0 { if i < 0 {
return return
} }

View File

@ -2,8 +2,6 @@ package nbconn
import ( import (
"sync" "sync"
"github.com/jackc/pgx/v5/internal/iobufpool"
) )
const minBufferQueueLen = 8 const minBufferQueueLen = 8
@ -70,7 +68,3 @@ func (bq *bufferQueue) growQueue() {
copy(newQueue, bq.queue) copy(newQueue, bq.queue)
bq.queue = newQueue bq.queue = newQueue
} }
func releaseBuf(buf []byte) {
iobufpool.Put(buf[:cap(buf)])
}

View File

@ -114,7 +114,7 @@ func (c *NetConn) Read(b []byte) (n int, err error) {
buf = buf[copiedN:] buf = buf[copiedN:]
c.readQueue.pushFront(buf) c.readQueue.pushFront(buf)
} else { } else {
releaseBuf(buf) iobufpool.Put(buf)
} }
n += copiedN n += copiedN
} }
@ -292,7 +292,7 @@ func (c *NetConn) flush() error {
} }
} }
releaseBuf(buf) iobufpool.Put(buf)
} }
return nil return nil