Reserve capacity when decoding HPACK headers (#118)

Motivation:

I was seeing frequent reallocations of the headers array as it
resized during decoding.

Modifications:

Reserve capacity for at least 16 HPACK headers during decoding.

Result:

Fewer reallocations at the cost of allocating more than we might need.
This commit is contained in:
George Barnett authored and Johannes Weiss committed 2019-05-16 14:31:19 +01:00
1 parent 6a97259a5d
commit d66cd24206
1 file changed
+1
+1
View File
@@ -89,6 +89,7 @@ public struct HPACKDecoder {
// take a local copy to mutate
var bufCopy = buffer
var headers: [HPACKHeader] = []
headers.reserveCapacity(16)
while bufCopy.readableBytes > 0 {
switch try self.decodeHeader(from: &bufCopy) {