mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-25 04:47:50 +00:00
Motivation: We were copying HTTP headers around quite a lot when transforming from HTTP/1 to HTTP/2 and back. Due to the different underlying representations we cannot get away from needing to do one copy, as the backing array storage is of a different type, but we were frequently incurring CoWs as well that were just totally unnecessary. Modifications: - Refactored the header code to work more confidently on HPACKHeaders. - Removed some mutating functions that triggered unnecessary CoWs. - Improved HPACKHeaders(httpHeaders:) initializer to avoid unnecessary intermediate array - Improved HTTPHeaders(requestHead:protocolString:) to avoid CoWs and reallocations - Improved HTTPHeaders(responseHead:) to avoid CoWs and reallocations Result: Fewer heap allocations