mirror of
https://github.com/apple/swift-http-types
synced 2026-11-24 04:37:51 +00:00
# Motivation Currently when initializing a Field Name, we create a canonical lowercased version of the field name. However, it is reasonable to expect that a significant amount of the time the users will insert a name string that is already lowercased, so turning it into lowercase creates an extra unnecessary allocation # Changes This changes the validation step for the name to compute in a single pass whether the name is valid and if it's already in the canonical lowercased format. If it's already lowercased, then we can skip the extra allocation and just reuse the same string. if it's valid but not lowercased we can default to the previous logic. For ultimate performance this iterates over Spans whenever we use Swift 6.4. For other Swift versions, we default to iterating over the UTF8View instead, which is slightly slower, but keeps us backwards compatible. # Result More performance