From b596fa34557d81a3ded6b1533964d47649afd2f8 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 30 Apr 2016 13:32:19 -0500 Subject: [PATCH] Avoid allocation for WriteBuf on query --- conn.go | 1 + messages.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 6faed577..a8c6cbc5 100644 --- a/conn.go +++ b/conn.go @@ -47,6 +47,7 @@ type Conn struct { lastActivityTime time.Time // the last time the connection was used reader *bufio.Reader // buffered reader to improve read performance wbuf [1024]byte + writeBuf WriteBuf Pid int32 // backend pid SecretKey int32 // key to use to send a cancel query message to the server RuntimeParams map[string]string // parameters that have been reported by the server diff --git a/messages.go b/messages.go index 7cc244c8..1fbd9cbc 100644 --- a/messages.go +++ b/messages.go @@ -91,7 +91,8 @@ func (self PgError) Error() string { func newWriteBuf(c *Conn, t byte) *WriteBuf { buf := append(c.wbuf[0:0], t, 0, 0, 0, 0) - return &WriteBuf{buf: buf, sizeIdx: 1, conn: c} + c.writeBuf = WriteBuf{buf: buf, sizeIdx: 1, conn: c} + return &c.writeBuf } // WrifeBuf is used build messages to send to the PostgreSQL server. It is used