Reuse write buffer.

This commit is contained in:
Vladimir Mihailenco 2014-07-13 15:07:37 +03:00
parent aff229a228
commit 97039c229c
2 changed files with 3 additions and 1 deletions

View File

@ -35,6 +35,7 @@ type pool interface {
type conn struct { type conn struct {
netcn net.Conn netcn net.Conn
rd *bufio.Reader rd *bufio.Reader
buf []byte
inUse bool inUse bool
usedAt time.Time usedAt time.Time
@ -53,6 +54,7 @@ func newConnFunc(dial func() (net.Conn, error)) func() (*conn, error) {
} }
cn := &conn{ cn := &conn{
netcn: netcn, netcn: netcn,
buf: make([]byte, 0, 64),
} }
cn.rd = bufio.NewReader(cn) cn.rd = bufio.NewReader(cn)
return cn, nil return cn, nil

View File

@ -14,7 +14,7 @@ type baseClient struct {
} }
func (c *baseClient) writeCmd(cn *conn, cmds ...Cmder) error { func (c *baseClient) writeCmd(cn *conn, cmds ...Cmder) error {
buf := make([]byte, 0, 64) buf := cn.buf[:0]
for _, cmd := range cmds { for _, cmd := range cmds {
buf = appendArgs(buf, cmd.args()) buf = appendArgs(buf, cmd.args())
} }