From 7e43eca3d3c7f71bfbdfa88cd8c05191400e2701 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 8 Aug 2016 16:31:01 -0500 Subject: [PATCH] Remove one allocation per pool query --- conn_pool.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/conn_pool.go b/conn_pool.go index 775fb091..9e468cbb 100644 --- a/conn_pool.go +++ b/conn_pool.go @@ -30,6 +30,8 @@ type ConnPool struct { pgTypes map[Oid]PgType pgsql_af_inet *byte pgsql_af_inet6 *byte + txAfterClose func(tx *Tx) + rowsAfterClose func(rows *Rows) } type ConnPoolStat struct { @@ -68,6 +70,14 @@ func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) { p.logLevel = LogLevelNone } + p.txAfterClose = func(tx *Tx) { + p.Release(tx.Conn()) + } + + p.rowsAfterClose = func(rows *Rows) { + p.Release(rows.Conn()) + } + p.allConnections = make([]*Conn, 0, p.maxConnections) p.availableConnections = make([]*Conn, 0, p.maxConnections) p.preparedStatements = make(map[string]*PreparedStatement) @@ -486,11 +496,3 @@ func (p *ConnPool) BeginIso(iso string) (*Tx, error) { return tx, nil } } - -func (p *ConnPool) txAfterClose(tx *Tx) { - p.Release(tx.Conn()) -} - -func (p *ConnPool) rowsAfterClose(rows *Rows) { - p.Release(rows.Conn()) -}