From b93773f50025fc1c14bbd7e97a3b170aae9a0977 Mon Sep 17 00:00:00 2001 From: Sergey Kamardin Date: Sat, 5 May 2018 22:46:26 +0300 Subject: [PATCH] write: apply BCE optimization to the WriteHeader(). --- write.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/write.go b/write.go index f3b26e3..3f7c19d 100644 --- a/write.go +++ b/write.go @@ -64,6 +64,7 @@ func WriteHeader(w io.Writer, h Header) error { Cap: MaxHeaderSize, } bts := *(*[]byte)(unsafe.Pointer(bh)) + _ = bts[MaxHeaderSize-1] // bounds check hint to compiler. if h.Fin { bts[0] |= bit0 @@ -79,12 +80,12 @@ func WriteHeader(w io.Writer, h Header) error { case h.Length <= len16: bts[1] = 126 - binary.BigEndian.PutUint16(bts[2:], uint16(h.Length)) + binary.BigEndian.PutUint16(bts[2:4], uint16(h.Length)) n = 4 case h.Length <= len64: bts[1] = 127 - binary.BigEndian.PutUint64(bts[2:], uint64(h.Length)) + binary.BigEndian.PutUint64(bts[2:10], uint64(h.Length)) n = 10 default: