mirror of
https://github.com/apple/swift-http-types
synced 2026-11-24 04:37:51 +00:00
### Motivation Currently constructing a request or response from parsed http fields requires multiple unnecessary allocations. Mainly due to: 1. Allocations from resizing the array as we keep appending more values to it 2. When running validation checks, we temporarily use an array of values to represent the values for a given field name. When those fields are set this requires an extra array allocation just to run the check ### Modifications - Reserve needed capacity during initial of parsed fields to prevent multiple subsequent allocations - Avoid allocating an array while validating content length, content disposition and location headers by validating them at insertion time and therefore only iterating once ### Result Reduction in allocations and instructions in benchmarks Co-authored-by: Fabian Fett <fabianfett@apple.com>