diff --git a/internal/iobufpool/iobufpool.go b/internal/iobufpool/iobufpool.go index 95fd21f5..9e55c435 100644 --- a/internal/iobufpool/iobufpool.go +++ b/internal/iobufpool/iobufpool.go @@ -37,9 +37,7 @@ func getPoolIdx(size int) int { // Put returns buf to the pool. func Put(buf []byte) { - buf = buf[:cap(buf)] - - i := putPoolIdx(len(buf)) + i := putPoolIdx(cap(buf)) if i < 0 { return } diff --git a/internal/nbconn/bufferqueue.go b/internal/nbconn/bufferqueue.go index fff6dc5b..138a9aa5 100644 --- a/internal/nbconn/bufferqueue.go +++ b/internal/nbconn/bufferqueue.go @@ -2,8 +2,6 @@ package nbconn import ( "sync" - - "github.com/jackc/pgx/v5/internal/iobufpool" ) const minBufferQueueLen = 8 @@ -70,7 +68,3 @@ func (bq *bufferQueue) growQueue() { copy(newQueue, bq.queue) bq.queue = newQueue } - -func releaseBuf(buf []byte) { - iobufpool.Put(buf[:cap(buf)]) -} diff --git a/internal/nbconn/nbconn.go b/internal/nbconn/nbconn.go index 97a5844f..82eb57ea 100644 --- a/internal/nbconn/nbconn.go +++ b/internal/nbconn/nbconn.go @@ -114,7 +114,7 @@ func (c *NetConn) Read(b []byte) (n int, err error) { buf = buf[copiedN:] c.readQueue.pushFront(buf) } else { - releaseBuf(buf) + iobufpool.Put(buf) } n += copiedN } @@ -292,7 +292,7 @@ func (c *NetConn) flush() error { } } - releaseBuf(buf) + iobufpool.Put(buf) } return nil