diff --git a/.swiftformat b/.swiftformat index bf31db9..d1f35ac 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,4 +1,4 @@ ---swiftversion 5.8 +--swiftversion 5.7 # file options diff --git a/Package.swift b/Package.swift index f5f8403..ebe6d92 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.8 +// swift-tools-version: 5.7 import PackageDescription diff --git a/Sources/HTTPTypes/ISOLatin1String.swift b/Sources/HTTPTypes/ISOLatin1String.swift index 5f501a4..d3b566e 100644 --- a/Sources/HTTPTypes/ISOLatin1String.swift +++ b/Sources/HTTPTypes/ISOLatin1String.swift @@ -32,7 +32,7 @@ struct ISOLatin1String: Sendable, Hashable { try withUnsafeTemporaryAllocation(of: UInt8.self, capacity: self._storage.unicodeScalars.count) { buffer in for (index, scalar) in self._storage.unicodeScalars.enumerated() { assert(scalar.value <= UInt8.max) - buffer.initializeElement(at: index, to: UInt8(truncatingIfNeeded: scalar.value)) + buffer[index] = UInt8(truncatingIfNeeded: scalar.value) } return try body(UnsafeBufferPointer(buffer)) } diff --git a/Sources/HTTPTypesFoundation/HTTPRequest+URL.swift b/Sources/HTTPTypesFoundation/HTTPRequest+URL.swift index 7e4eca2..db93678 100644 --- a/Sources/HTTPTypesFoundation/HTTPRequest+URL.swift +++ b/Sources/HTTPTypesFoundation/HTTPRequest+URL.swift @@ -95,12 +95,12 @@ extension URL { return CFRange(location: a.location, length: b.location + b.length - a.location) } - func bufferSlice(_ range: CFRange) -> some Collection { - buffer[range.location ..< range.location + range.length] + func bufferSlice(_ range: CFRange) -> UnsafeMutableBufferPointer { + UnsafeMutableBufferPointer(rebasing: buffer[range.location ..< range.location + range.length]) } let schemeRange = CFURLGetByteRangeForComponent(url, .scheme, nil) - precondition(schemeRange.location != kCFNotFound, "") + precondition(schemeRange.location != kCFNotFound, "Schemeless URL is not supported") let scheme = Array(bufferSlice(schemeRange)) let authority: [UInt8]? @@ -123,9 +123,9 @@ extension URL { } else { let pathBuffer = bufferSlice(requestPathRange) path = [UInt8](unsafeUninitializedCapacity: pathBuffer.count + 1) { buffer, initializedCount in - buffer.initializeElement(at: 0, to: 0x2F) - let endIndex = buffer[1...].initialize(fromContentsOf: pathBuffer) - initializedCount = buffer.distance(from: buffer.startIndex, to: endIndex) + buffer[0] = 0x2F + UnsafeMutableRawBufferPointer(UnsafeMutableBufferPointer(rebasing: buffer[1...])).copyMemory(from: UnsafeRawBufferPointer(pathBuffer)) + initializedCount = pathBuffer.count + 1 } } } else { diff --git a/Sources/HTTPTypesFoundation/HTTPTypes+ISOLatin1.swift b/Sources/HTTPTypesFoundation/HTTPTypes+ISOLatin1.swift index b2063cf..19708cf 100644 --- a/Sources/HTTPTypesFoundation/HTTPTypes+ISOLatin1.swift +++ b/Sources/HTTPTypesFoundation/HTTPTypes+ISOLatin1.swift @@ -28,9 +28,9 @@ extension HTTPField { self = withUnsafeTemporaryAllocation(of: UInt8.self, capacity: isoLatin1Value.unicodeScalars.count) { buffer in for (index, scalar) in isoLatin1Value.unicodeScalars.enumerated() { if scalar.value > UInt8.max { - buffer.initializeElement(at: index, to: 0x20) + buffer[index] = 0x20 } else { - buffer.initializeElement(at: index, to: UInt8(truncatingIfNeeded: scalar.value)) + buffer[index] = UInt8(truncatingIfNeeded: scalar.value) } } return HTTPField(name: name, value: buffer)