mirror of https://github.com/jackc/pgx.git
Simplify iobufpool usage
parent
60ecdda02e
commit
6b63ceee07
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)])
|
|
||||||
}
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue