From 78d2884cedb8a50530c9f585f7f718469397818e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 24 Feb 2020 17:15:20 +0300 Subject: [PATCH] allocations improvements and tunnel fixes (#1248) * reduce allocations in tunnel code Signed-off-by: Vasiliy Tolstov * another allocation fix Signed-off-by: Vasiliy Tolstov * allocate maps with len if it known Signed-off-by: Vasiliy Tolstov * allocate key for send once Signed-off-by: Vasiliy Tolstov --- codec.go | 2 +- subscriber.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codec.go b/codec.go index eb1b09c..db9706d 100644 --- a/codec.go +++ b/codec.go @@ -140,7 +140,7 @@ func (g *grpcCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error { m = new(codec.Message) } if m.Header == nil { - m.Header = make(map[string]string) + m.Header = make(map[string]string, len(md)) } for k, v := range md { m.Header[k] = strings.Join(v, ",") diff --git a/subscriber.go b/subscriber.go index 7bd39a5..a29ebcb 100644 --- a/subscriber.go +++ b/subscriber.go @@ -188,7 +188,7 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke return err } - hdr := make(map[string]string) + hdr := make(map[string]string, len(msg.Header)) for k, v := range msg.Header { hdr[k] = v }