Merge pull request #2 from guoye-zhang/version

Reduce Swift version requirement to 5.7
This commit is contained in:
Guoye Zhang authored and GitHub committed 2023-07-10 11:26:04 -07:00
commit 39661f4ca8
5 files changed
+11 -11

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
+1 -1
View File
@@ -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))
}
@@ -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,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 {
@@ -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)