allocations improvements and tunnel fixes (#1248)

* reduce allocations in tunnel code

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* another allocation fix

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* allocate maps with len if it known

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* allocate key for send once

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-02-24 17:15:20 +03:00
committed by GitHub
parent 01d88601c0
commit 5b0175c2e5
13 changed files with 58 additions and 31 deletions

View File

@@ -156,7 +156,7 @@ func (h *httpTransportClient) Recv(m *Message) error {
m.Body = b
if m.Header == nil {
m.Header = make(map[string]string)
m.Header = make(map[string]string, len(rsp.Header))
}
for k, v := range rsp.Header {
@@ -193,10 +193,6 @@ func (h *httpTransportSocket) Recv(m *Message) error {
return errors.New("message passed in is nil")
}
if m.Header == nil {
m.Header = make(map[string]string)
}
// process http 1
if h.r.ProtoMajor == 1 {
// set timeout if its greater than 0
@@ -228,6 +224,10 @@ func (h *httpTransportSocket) Recv(m *Message) error {
r.Body.Close()
m.Body = b
if m.Header == nil {
m.Header = make(map[string]string, len(r.Header))
}
// set headers
for k, v := range r.Header {
if len(v) > 0 {