Reduce Swift version requirement to 5.7

This commit is contained in:
Guoye Zhang committed 2023-07-06 22:52:11 -07:00
1 parent ae848811f9
commit 885b94bd13
5 files changed
+23 -5

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
--swiftversion 5.8
--swiftversion 5.7
# file options
+1 -1
View File
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 5.7
import PackageDescription
+4
View File
@@ -32,7 +32,11 @@ 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)
#if swift(>=5.8)
buffer.initializeElement(at: index, to: UInt8(truncatingIfNeeded: scalar.value))
#else
buffer[index] = UInt8(truncatingIfNeeded: scalar.value)
#endif
}
return try body(UnsafeBufferPointer(buffer))
}
@@ -95,12 +95,12 @@ extension URL {
return CFRange(location: a.location, length: b.location + b.length - a.location)
}
func bufferSlice(_ range: CFRange) -> some Collection<UInt8> {
buffer[range.location ..< range.location + range.length]
func bufferSlice(_ range: CFRange) -> UnsafeMutableBufferPointer<UInt8> {
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,8 +123,14 @@ extension URL {
} else {
let pathBuffer = bufferSlice(requestPathRange)
path = [UInt8](unsafeUninitializedCapacity: pathBuffer.count + 1) { buffer, initializedCount in
#if swift(>=5.8)
buffer.initializeElement(at: 0, to: 0x2F)
let endIndex = buffer[1...].initialize(fromContentsOf: pathBuffer)
#else
buffer[0] = 0x2F
memcpy(buffer.baseAddress!.advanced(by: 1), pathBuffer.baseAddress!, pathBuffer.count)
let endIndex = buffer.startIndex.advanced(by: pathBuffer.count + 1)
#endif
initializedCount = buffer.distance(from: buffer.startIndex, to: endIndex)
}
}
@@ -28,9 +28,17 @@ 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 {
#if swift(>=5.8)
buffer.initializeElement(at: index, to: 0x20)
#else
buffer[index] = 0x20
#endif
} else {
#if swift(>=5.8)
buffer.initializeElement(at: index, to: UInt8(truncatingIfNeeded: scalar.value))
#else
buffer[index] = UInt8(truncatingIfNeeded: scalar.value)
#endif
}
}
return HTTPField(name: name, value: buffer)