Skip to content

Commit

Permalink
Revert argument changes
Browse files Browse the repository at this point in the history
  • Loading branch information
guoye-zhang committed Dec 2, 2023
1 parent 28a5f3a commit fee4574
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ needs to be listed here.

- Franz Busch <[email protected]>
- Guoye Zhang <[email protected]>
- Gwynne Raskind <[email protected]>
- Jager-yoo <[email protected]>
- Sergey Dmitriev <[email protected]>
- Tim Condon <[email protected]>
- Tomohiro Kumagai <[email protected]>

**Updating this list**
Expand Down
8 changes: 4 additions & 4 deletions Sources/HTTPTypes/HTTPField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public struct HTTPField: Sendable, Hashable {
/// - Parameters:
/// - name: The HTTP field name.
/// - value: The HTTP field value. Invalid bytes are converted into space characters.
public init<C: Collection>(name: Name, value: C) where C.Element == UInt8 {
public init(name: Name, value: some Collection<UInt8>) {
self.name = name
self.rawValue = Self.legalizeValue(ISOLatin1String(value))
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public struct HTTPField: Sendable, Hashable {

var rawValue: ISOLatin1String

private static func _isValidValue<S: Sequence>(_ bytes: S) -> Bool where S.Element == UInt8 {
private static func _isValidValue(_ bytes: some Sequence<UInt8>) -> Bool {
var iterator = bytes.makeIterator()
guard var byte = iterator.next() else {
// Empty string is allowed.
Expand Down Expand Up @@ -178,7 +178,7 @@ public struct HTTPField: Sendable, Hashable {
///
/// - Parameter value: The byte collection to validate.
/// - Returns: Whether the byte collection is valid.
public static func isValidValue<C: Collection>(_ value: C) -> Bool where C.Element == UInt8 {
public static func isValidValue(_ value: some Collection<UInt8>) -> Bool {
self._isValidValue(value)
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ extension HTTPField: Codable {
}

extension HTTPField {
static func isValidToken<S: StringProtocol>(_ token: S) -> Bool {
static func isValidToken(_ token: some StringProtocol) -> Bool {
!token.isEmpty && token.utf8.allSatisfy {
switch $0 {
case 0x21, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2A, 0x2B, 0x2D, 0x2E, 0x5E, 0x5F, 0x60, 0x7C, 0x7E:
Expand Down
4 changes: 2 additions & 2 deletions Sources/HTTPTypes/HTTPFields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public struct HTTPFields: Sendable, Hashable {
return HTTPFieldSequence(fields: self._storage.fields, index: index)
}

private mutating func setFields<S: Sequence>(_ fieldSequence: S, for name: HTTPField.Name) where S.Element == HTTPField {
private mutating func setFields(_ fieldSequence: some Sequence<HTTPField>, for name: HTTPField.Name) {
if !isKnownUniquelyReferenced(&self._storage) {
self._storage = self._storage.copy()
}
Expand Down Expand Up @@ -384,7 +384,7 @@ extension HTTPFields: Codable {

extension Array {
// `removalIndices` must be ordered.
mutating func remove<S: Sequence>(at removalIndices: S) where S.Element == Index {
mutating func remove(at removalIndices: some Sequence<Index>) {
var offset = 0
var iterator = removalIndices.makeIterator()
var nextToRemoveOptional = iterator.next()
Expand Down
4 changes: 2 additions & 2 deletions Sources/HTTPTypes/ISOLatin1String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension String {
struct ISOLatin1String: Sendable, Hashable {
let _storage: String

private static func transcodeSlowPath<C: Collection>(from bytes: C) -> String where C.Element == UInt8 {
private static func transcodeSlowPath(from bytes: some Collection<UInt8>) -> String {
let scalars = bytes.lazy.map { UnicodeScalar(UInt32($0))! }
var string = ""
string.unicodeScalars.append(contentsOf: scalars)
Expand All @@ -46,7 +46,7 @@ struct ISOLatin1String: Sendable, Hashable {
}
}

init<C: Collection>(_ bytes: C) where C.Element == UInt8 {
init(_ bytes: some Collection<UInt8>) {
let ascii = bytes.allSatisfy { $0 & 0x80 == 0 }
if ascii {
self._storage = String(decoding: bytes, as: UTF8.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/HTTPTypesFoundation/HTTPRequest+URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension HTTPRequest {
}

extension URL {
fileprivate init?<C1: Collection, C2: Collection, C3: Collection>(scheme: C1, authority: C2, path: C3) where C1.Element == UInt8, C2.Element == UInt8, C3.Element == UInt8 {
fileprivate init?(scheme: some Collection<UInt8>, authority: some Collection<UInt8>, path: some Collection<UInt8>) {
var buffer = [UInt8]()
buffer.reserveCapacity(scheme.count + 3 + authority.count + path.count)
buffer.append(contentsOf: scheme)
Expand Down
2 changes: 1 addition & 1 deletion Tests/HTTPTypesTests/HTTPTypesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ final class HTTPTypesTests: XCTestCase {
}

func testSendable() {
func isSendable<T: Sendable>(_ value: T) -> Bool { true }
func isSendable(_ value: some Sendable) -> Bool { true }
func isSendable(_ value: Any) -> Bool { false }

let field: HTTPField = .init(name: .userAgent, value: "")
Expand Down

0 comments on commit fee4574

Please sign in to comment.