Commit 69d4b8aa authored by Meir Fischer's avatar Meir Fischer Committed by Brad Fitzpatrick

http2: remove unnecessary TODO for trailer keys allocation

strings.Join has two allocations:
(1) []byte intermediate
(2) final string conversion
The comma-separated keys are ultimately stored in hpack.HeaderField.Value
as a string so (2) is not wasteful. Because strings.Join is used so heavily
I assume its implementation is optimal - (1) is necessary.
Therefore, short of refactoring hpack.HeaderField's Value type, the status quo
seems optimal.

This TODO appears to have been copy-pasted from net/http/transfer.go
However, the two cases are different. transfer.go has two allocations
in addition to strings.Join: concatenation with literals and converting
string to bytes in io.WriteString.

Change-Id: I292203a6535dd2774f5bf45e7280b89aabb5d78d
Reviewed-on: https://go-review.googlesource.com/34626Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 8fd7f259
...@@ -658,8 +658,6 @@ func commaSeparatedTrailers(req *http.Request) (string, error) { ...@@ -658,8 +658,6 @@ func commaSeparatedTrailers(req *http.Request) (string, error) {
} }
if len(keys) > 0 { if len(keys) > 0 {
sort.Strings(keys) sort.Strings(keys)
// TODO: could do better allocation-wise here, but trailers are rare,
// so being lazy for now.
return strings.Join(keys, ","), nil return strings.Join(keys, ","), nil
} }
return "", nil return "", nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment