From 470a181846e4434b7aab251d0778462f688ecfb3 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Fri, 20 May 2016 23:58:29 -0400 Subject: [PATCH] Framer does not need to allocate a slice for each execution --- pkg/util/framer/framer.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/util/framer/framer.go b/pkg/util/framer/framer.go index 615d07de1cc..7ca806fa054 100644 --- a/pkg/util/framer/framer.go +++ b/pkg/util/framer/framer.go @@ -25,6 +25,7 @@ import ( type lengthDelimitedFrameWriter struct { w io.Writer + h [4]byte } func NewLengthDelimitedFrameWriter(w io.Writer) io.Writer { @@ -34,13 +35,12 @@ func NewLengthDelimitedFrameWriter(w io.Writer) io.Writer { // Write writes a single frame to the nested writer, prepending it with the length in // in bytes of data (as a 4 byte, bigendian uint32). func (w *lengthDelimitedFrameWriter) Write(data []byte) (int, error) { - header := [4]byte{} - binary.BigEndian.PutUint32(header[:], uint32(len(data))) - n, err := w.w.Write(header[:]) + binary.BigEndian.PutUint32(w.h[:], uint32(len(data))) + n, err := w.w.Write(w.h[:]) if err != nil { return 0, err } - if n != len(header) { + if n != len(w.h) { return 0, io.ErrShortWrite } return w.w.Write(data)