From a7fd74b55d138ffdffa6fbe72f716e17d56b6d67 Mon Sep 17 00:00:00 2001 From: Jeremy Schlatter Date: Fri, 2 Dec 2016 13:32:11 -0800 Subject: [PATCH] pre-allocate --- vncclient/client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vncclient/client.go b/vncclient/client.go index ba86a98..dc08275 100644 --- a/vncclient/client.go +++ b/vncclient/client.go @@ -211,7 +211,7 @@ func (c *ClientConn) KeyEvent(keysym uint32, down bool) error { c.send.Lock() defer c.send.Unlock() - var buf bytes.Buffer + buf := bytes.NewBuffer(make([]byte, 0, 8)) var downFlag uint8 if down { @@ -226,7 +226,7 @@ func (c *ClientConn) KeyEvent(keysym uint32, down bool) error { keysym, } for _, val := range data { - if err := binary.Write(&buf, binary.BigEndian, val); err != nil { + if err := binary.Write(buf, binary.BigEndian, val); err != nil { return err } } @@ -249,7 +249,7 @@ func (c *ClientConn) PointerEvent(mask ButtonMask, x, y uint16) error { c.send.Lock() defer c.send.Unlock() - var buf bytes.Buffer + buf := bytes.NewBuffer(make([]byte, 0, 6)) data := []interface{}{ uint8(5), @@ -259,7 +259,7 @@ func (c *ClientConn) PointerEvent(mask ButtonMask, x, y uint16) error { } for _, val := range data { - if err := binary.Write(&buf, binary.BigEndian, val); err != nil { + if err := binary.Write(buf, binary.BigEndian, val); err != nil { return err } }