Skip to content

Commit

Permalink
Eliminate hasPrefix usage for pseudo HTTP header names (#248)
Browse files Browse the repository at this point in the history
UTF8 view is faster than hasPrefix

rdar://144395951
  • Loading branch information
guoye-zhang authored Feb 16, 2025
1 parent 926c3e1 commit 00f3f72
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/NIOHTTPTypesHTTP2/HTTPTypeConversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extension HTTPRequest {
var i = hpack.startIndex
while i != hpack.endIndex {
let (name, value, indexable) = hpack[i]
if !name.hasPrefix(":") {
if name.utf8.first != UInt8(ascii: ":") {
break
}
switch name {
Expand Down Expand Up @@ -180,7 +180,7 @@ extension HTTPRequest {
self.headerFields.reserveCapacity(hpack.count)
while i != hpack.endIndex {
let (name, value, indexable) = hpack[i]
if name.hasPrefix(":") {
if name.utf8.first == UInt8(ascii: ":") {
throw HTTP2TypeConversionError.pseudoFieldNotFirst
}
if let fieldName = HTTPField.Name(name) {
Expand All @@ -201,7 +201,7 @@ extension HTTPResponse {
var i = hpack.startIndex
while i != hpack.endIndex {
let (name, value, indexable) = hpack[i]
if !name.hasPrefix(":") {
if name.utf8.first != UInt8(ascii: ":") {
break
}
switch name {
Expand Down Expand Up @@ -232,7 +232,7 @@ extension HTTPResponse {
self.headerFields.reserveCapacity(hpack.count)
while i != hpack.endIndex {
let (name, value, indexable) = hpack[i]
if name.hasPrefix(":") {
if name.utf8.first == UInt8(ascii: ":") {
throw HTTP2TypeConversionError.pseudoFieldNotFirst
}
if let fieldName = HTTPField.Name(name) {
Expand All @@ -251,7 +251,7 @@ extension HTTPFields {
self.reserveCapacity(trailers.count)

for (name, value, indexable) in trailers {
if name.hasPrefix(":") {
if name.utf8.first == UInt8(ascii: ":") {
throw HTTP2TypeConversionError.pseudoFieldInTrailers
}
if let fieldName = HTTPField.Name(name) {
Expand Down

0 comments on commit 00f3f72

Please sign in to comment.